<?php 
defined('IN_YYS')or exit('Access Denied.');
System::DOWN_App_class('base','member','no');
System::DOWN_App_fun('my','index');
System::DOWN_App_fun('user','index');
System::DOWN_sys_fun('send');
System::DOWN_sys_fun('user');
class ajax extends base {
     private $Mcartlist;
    
	public function __construct(){ 
		parent::__construct();
/* 		if(DOWN_A!='userphotoup' and DOWN_A!='singphotoup'){
			if(!$this->userinfo)_notemobile("请登录",LOCAL_PATH."/mobile/user/login",3);
		}	 */	
		$this->db = System::DOWN_sys_class('model');
		$uid=intval(_encrypt(_getcookie("uid"),'DECODE'));	
		$this->userinfo=$this->db->YOne("SELECT * from `@#_yonghu` where `uid` = '$uid'");

		//查询购物车的信息
		$Mcartlist = _getcookie("Cartlist");
		$this->Mcartlist=json_decode(stripslashes($Mcartlist),true);	
		
		//直购
		$Cartlistzg = _getcookie('Cartlistzg');
		$this->Cartlistzg=json_decode(stripslashes($Cartlistzg),true);	
	}
	public function init(){
	    if(DOWN_A!='userphotoup' and DOWN_A!='singphotoup'){
			if(!$this->userinfo)_notemobile("请登录",LOCAL_PATH."/mobile/user/login",3);
		}
		
		$huiyuan=$this->userinfo;
		$biaoti="我的汇格同城中心";	
		 
		 $weer['code']=1;
		 $weer['username']=huode_user_name($huiyuan['uid']);
		 $weer['uid']=$huiyuan['uid'];
		 if(!empty($huiyuan)){
		   $weer['code']=0;
		 }
		 
		echo json_encode($weer);
		 
		 
	}
//二维码带头像

	public function erweima(){
		$mysql_model=System::DOWN_sys_class('model');
        $huiyuan=$this->userinfo;
        if($this->segment(4) != null){

            $huiyuan = $this->userinfo;
            if (!$huiyuan && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
                header("location: " . LOCAL_PATH . "/mobile/user/wxloginer/");
                exit;
            }
            $lianjie = $this->db->Ylist("select * from `@#_yongjin` order by id desc limit 1");

            include_once((dirname(dirname(dirname(dirname(__FILE__)))) . '/phpqrcode/phpqrcode.php'));
            foreach ($lianjie as $key => $val) {
                $value = $val['link'].'?'.$this->segment(4);//二维码内容
            }


            $errorCorrectionLevel = 'H';//容错级别
            $matrixPointSize = 6;//生成图片大小
//生成二维码图片 
            QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
            $logo = YYS_UPLOADS_PATH . '/' . $huiyuan['img'];//准备好的logo图片

            $QR = 'qrcode.png';//已经生成的原始二维码图

            if ($logo !== FALSE) {
                $QR = imagecreatefromstring(file_get_contents($QR));
                $logo = imagecreatefromstring(file_get_contents($logo));
                $QR_width = imagesx($QR);//二维码图片宽度
                $QR_height = imagesy($QR);//二维码图片高度
                $logo_width = imagesx($logo);//logo图片宽度
                $logo_height = imagesy($logo);//logo图片高度
                $logo_qr_width = $QR_width / 5;
                $scale = $logo_width / $logo_qr_width;
                $logo_qr_height = $logo_height / $scale;
                $from_width = ($QR_width - $logo_qr_width) / 2;
                //重新组合图片并调整大小
                imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
                    $logo_qr_height, $logo_width, $logo_height);
            }
        }else{
            $lianjie = $this->db->Ylist("select * from `@#_yongjin` order by id desc limit 1");

            $huiyuan = $this->userinfo;
            if (!$huiyuan && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
                header("location: " . LOCAL_PATH . "/mobile/user/wxloginer/");
                exit;
            }
            foreach ($lianjie as $key => $val) {
                $yys['urls'][$key]['object_type'] = "";
                $yys['urls'][$key]['result'] = 'true';
                $yys['urls'][$key]['title'] = $val[title];

                if ($huiyuan[yaoqing] && empty($huiyuan[yaoqing2]) && empty($huiyuan[yaoqing3])) {
                    $yys['urls'][$key]['url_short'] = $val[link] . '?yaoqing2=' . $huiyuan[yaoqing] . '&yaoqing=' . $huiyuan[uid];
                } else if ($huiyuan[yaoqing] && $huiyuan[yaoqing2] && empty($huiyuan[yaoqing3])) {
                    $yys['urls'][$key]['url_short'] = $val[link] . '?yaoqing=' . $huiyuan[uid] . '&yaoqing2=' . $huiyuan[yaoqing] . '&yaoqing3=' . $huiyuan[yaoqing2];
                } else if ($huiyuan[yaoqing] && $huiyuan[yaoqing2] && $huiyuan[yaoqing3]) {
                    $yys['urls'][$key]['url_short'] = $val[link] . '?yaoqing=' . $huiyuan[uid] . '&yaoqing2=' . $huiyuan[yaoqing] . '&yaoqing3=' . $huiyuan[yaoqing2];
                } else {
                    $yys['urls'][$key]['url_short'] = $val[link] . '?yaoqing=' . $huiyuan[uid];
                }
                $yys['urls'][$key]['object_id'] = "";
                $yys['urls'][$key]['url_long'] = $val[link];
                $yys['urls'][$key]['type'] = "0";
            }


            include_once((dirname(dirname(dirname(dirname(__FILE__)))) . '/phpqrcode/phpqrcode.php'));
            $value = $yys['urls'][0]['url_short'];//二维码内容

            $errorCorrectionLevel = 'H';//容错级别
            $matrixPointSize = 6;//生成图片大小
//生成二维码图片
            QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
            $logo = YYS_UPLOADS_PATH . '/' . $huiyuan['img'];//准备好的logo图片

            $QR = 'qrcode.png';//已经生成的原始二维码图

            if ($logo !== FALSE) {
                $QR = imagecreatefromstring(file_get_contents($QR));
                $logo = imagecreatefromstring(file_get_contents($logo));
                $QR_width = imagesx($QR);//二维码图片宽度
                $QR_height = imagesy($QR);//二维码图片高度
                $logo_width = imagesx($logo);//logo图片宽度
                $logo_height = imagesy($logo);//logo图片高度
                $logo_qr_width = $QR_width / 5;
                $scale = $logo_width / $logo_qr_width;
                $logo_qr_height = $logo_height / $scale;
                $from_width = ($QR_width - $logo_qr_width) / 2;
                //重新组合图片并调整大小
                imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
                    $logo_qr_height, $logo_width, $logo_height);
            }
        }
    //输出图片
    Header("Content-type: image/png");
    ImagePng($QR);


	}

	public function erweimas(){
		$mysql_model=System::DOWN_sys_class('model');
        $huiyuan=$this->userinfo;
	if(!$huiyuan&&strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false){
			header("location: ".LOCAL_PATH."/mobile/user/wxloginer/");
			//header("location: ".LOCAL_PATH."/mobile/user/login");
			exit;
		}

	include templates("mobile/invite","erweima");
	}
	//幻灯
	public function getshorturl(){
		$lianjie=$this->db->Ylist("select * from `@#_yongjin` order by id desc limit 1");
	$huiyuan=$this->userinfo;
	foreach ($lianjie as $key=>$val){
	$yys['urls'][$key]['object_type']="";
	$yys['urls'][$key]['result']='true';
	$yys['urls'][$key]['title']=$val[title];

	if($huiyuan[yaoqing]&&empty($huiyuan[yaoqing2])&&empty($huiyuan[yaoqing3])){
	$yys['urls'][$key]['url_short']=$val[link].'?yaoqing2='.$huiyuan[yaoqing].'&yaoqing='.$huiyuan[uid];
	}else if($huiyuan[yaoqing]&&$huiyuan[yaoqing2]&&empty($huiyuan[yaoqing3])){
		$yys['urls'][$key]['url_short']=$val[link].'?yaoqing='.$huiyuan[uid].'&yaoqing2='.$huiyuan[yaoqing].'&yaoqing3='.$huiyuan[yaoqing2];
	}else if($huiyuan[yaoqing]&&$huiyuan[yaoqing2]&&$huiyuan[yaoqing3]){
		$yys['urls'][$key]['url_short']=$val[link].'?yaoqing='.$huiyuan[uid].'&yaoqing2='.$huiyuan[yaoqing].'&yaoqing3='.$huiyuan[yaoqing2];
	}else{
		$yys['urls'][$key]['url_short']=$val[link].'?yaoqing='.$huiyuan[uid];
	}
	$yys['urls'][$key]['object_id']="";
	$yys['urls'][$key]['url_long']=$val[link];
	$yys['urls'][$key]['type']="0";
	}
	echo json_encode($yys);
	}
	public function slides(){
	  $sql="select * from `@#_shouji` where 1";
	  $SlideList=$this->db->Ylist($sql);
	  if(empty($SlideList)){
	    $slides['state']=1;
	  }else{
	   $slides['state']=0;
	    foreach($SlideList as $key=>$val){
		   $shopid = ereg_replace('[^0-9]','',$val['link']);
		  // $shopid=explode("/",$val['link']);
		   $slides['listItems'][$key]['alt']=$val['color'];
//		   $slides['listItems'][$key]['url']=LOCAL_PATH."/mobile/mobile/item/".$shopid;
		   $slides['listItems'][$key]['url']=$val['link'];
		   $slides['listItems'][$key]['src']=YYS_LOCAL_PATH."/statics/uploads/".$val['img'];
		   $slides['listItems'][$key]['width']='614PX';
		   $slides['listItems'][$key]['height']='110PX';
		
		}
	   
	  }
	   echo json_encode($slides);
	}		
	
   // 今日揭晓商品
    public function show_jrjxshop(){
		$fenyetime=safe_replace($this->segment(4));
		
		
		$w_jinri_time = strtotime(date('Y-m-d'));
		$w_minri_time = strtotime(date('Y-m-d',strtotime("+1 day")));
		
		
		$jinri_shoplist = $this->db->Ylist("select * from `@#_shangpin` where `xsjx_time` > '$w_jinri_time' and `xsjx_time` < '$w_minri_time' order by xsjx_time limit 0,3 ");
		
		if(!empty($jinri_shoplist)){
		   $m['errorCode']=0;
		}else{
		   $m['errorCode']=1;
		}
		//echo $fenyetime;
		echo json_encode($m);
	
	}	
	//首页商品
	public function shouye(){
	
		//最新揭晓
		
		
	$_GET = array_change_key_case($_GET, CASE_LOWER);
		$order =htmlspecialchars($_GET[orderflag]);
	$kaishi=htmlspecialchars($_GET[fidx]);

	$jieshu=htmlspecialchars($_GET[eidx]);
        if($kaishi == 1) {
            $kaishi = $kaishi - 1;
        }
		switch($order){
			case  '50':
				
				$orders = "where `q_end_time` is null and uid = 0 order by `id` DESC";
			break;
			case  '20':
				$orders = 'where `q_end_time` is null and uid = 0 and `renqi`=1 order by `shenyurenshu` DESC';
			break;
			case  '31':
				$orders = 'where `q_end_time` is null and uid = 0 order by `money` DESC';
			break;
			case  '30':
				$orders = 'where `q_end_time` is null and uid = 0 order by `money` ASC';
			break;
			default:
			//echo $jieshu;
				$orders = 'where `q_end_time` is null and uid = 0 order by `canyurenshu`/`zongrenshu` DESC';
		
		}
		$shouyelist=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,yunjiage  from `@#_shangpin` $orders limit $kaishi,$jieshu;");
		$count=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,yunjiage  from `@#_shangpin`");
		if($shouyelist){
		$yyslist['code']=0;
		}
		$yyslist['count']=count($count);
		 foreach($shouyelist as $key=>$val){
			
$yyslist['listItems'][$key]['rowid']=0;
$yyslist['listItems'][$key]['goodsid']=$val['id'];
$yyslist['listItems'][$key]['goodssnme']=$val['title'];
$yyslist['listItems'][$key]['goodspic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
$yyslist['listItems'][$key]['codeid']=$val['id'];
$yyslist['listItems'][$key]['codeprice']=$val['money'];
$yyslist['listItems'][$key]['codequantity']=$val['zongrenshu'];
$yyslist['listItems'][$key]['codesales']=$val['canyurenshu'];
$yyslist['listItems'][$key]['platform']=$val['platform'];
$yyslist['listItems'][$key]['codesales2']=$val['discountPrice'];
$yyslist['listItems'][$key]['codeperiod']=$val['qishu'];
$yyslist['listItems'][$key]['codetype']=0;
$yyslist['listItems'][$key]['goodstag']=0;
$yyslist['listItems'][$key]['yunjiage']=$val['yunjiage'];
$yyslist['listItems'][$key]['codelimitbuy']=0;
		
		 }       
          
echo json_encode($yyslist);
	
	}
	//获得商品列表
	public function getGoodsPageList(){
		$_GET = array_change_key_case($_GET, CASE_LOWER);
		$webname=$this->_yys['web_name'];
		$cate_band =htmlspecialchars($_GET[sortid]);
		//var_dump($cate_band);
		$select =htmlspecialchars($_GET[orderflag]);	
		$order =htmlspecialchars($_GET[orderflag]);
		$kaishi=htmlspecialchars($_GET[fidx]);
		$jieshu=htmlspecialchars($_GET[eidx]);
		$p =$kaishi;	
		$sun_cate = $this->db->Ylist("SELECT cateid from `@#_fenlei` where `parentid` = '$cate_band'");
		foreach($sun_cate as $v){
			$sun_id_str .= $v['cateid'].",";
			//var_dump($sun_id_str);
		}
		$sun_id_str .= $cate_band.",";
		$newstr = substr($sun_id_str,0,strlen($sun_id_str)-1);

		if($newstr){
			if(!$select){
				$select = '10';
			}		
			if($cate_band){
				$fen1 = intval($cate_band);	
				$cate_band = 'list';			
			}
			//var_dump($fen1);
			if(empty($fen1)){
				$pinpai=$this->db->Ylist("select * from `@#_pinpai` where 1 order by `order` DESC");	
				$daohangs = '所有分类';	
			}else{
				$pinpai=$this->db->Ylist("select * from `@#_pinpai` where `cateid`='$fen1' order by `order` DESC");
				$daohangs=$this->db->YOne("select * from `@#_fenlei` where `cateid` = '$fen1' order by `order` DESC");			
				$daohangs = $daohangs['name'];			
			}	
				
			$fenlei=$this->db->Ylist("select * from `@#_fenlei` where `model` = '1'");
			

			//

			
			//分页
			
			$end=$jieshu;
			
			//var_dump($end);
			$star=($p-1);
			//var_dump($star);
			$select_w = '';

			if($select == 10){
				$select_w = 'order by `canyurenshu`/`zongrenshu` DESC';
			}
			if($select == 20){
				$select_w = "and `renqi` = '1'";
			}
			if($select == 30){
				$select_w = 'order by `canyurenshu`/`zongrenshu` DESC';
			}
			if($select == 40){
				$select_w = 'order by `shenyurenshu` ASC';
			}
			/*if($select == 30){
				$select_w = 'order by `money` DESC';
			}*/
			if($select == 31){
				$select_w = 'order by `money` ASC';
			}
			if($select == 50){
				$select_w = 'order by `id` DESC';
			}
			if($select == 60){
				$select_w = 'order by `money` DESC';
			}

			
			//var_dump($newstr);	 
			if($fen1){		
				$count=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and `q_uid` is null and `cateid` in ($newstr) $select_w");
			}else{			
				$count=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null $select_w");
			}
			if($fen1){
				
				$yyslist=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null and `cateid` in ($newstr) $select_w limit $star,$end");
			
			}else{	
				
				$yyslist=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null $select_w limit $star,$end");
			} 
			}
			//var_dump(count($yyslist));
			
			
			//var_dump($yyslist);
			if($yyslist){
			$yyslist1['code']=0;
			$yyslist1['count']=count($count);
			foreach($yyslist as $key=>$val){
				
	$yyslist1['listItems'][$key]['rowid']=0;
	$yyslist1['listItems'][$key]['goodsid']=$val['id'];
	$yyslist1['listItems'][$key]['goodssnme']=$val['title'];
	$yyslist1['listItems'][$key]['goodspic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
	$yyslist1['listItems'][$key]['codeid']=$val['id'];
	$yyslist1['listItems'][$key]['codeprice']=$val['money'];
	$yyslist1['listItems'][$key]['codequantity']=$val['zongrenshu'];
	$yyslist1['listItems'][$key]['codesales']=$val['canyurenshu'];
	$yyslist1['listItems'][$key]['codeperiod']=$val['qishu'];
	$yyslist1['listItems'][$key]['codetype']=0;
	$yyslist1['listItems'][$key]['goodstag']=0;
	$yyslist1['listItems'][$key]['codelimitbuy']=0;
			}
			
			
		}
		else{
				$yyslist1['code']=1;
			}
	echo json_encode($yyslist1);
}
//直购商品列表
public function getGoodsPageListzg(){
	$_GET = array_change_key_case($_GET, CASE_LOWER);
	    $webname=$this->_yys['web_name'];
		$cate_band =htmlspecialchars($_GET[sortid]);
		//var_dump($cate_band);
		$select =htmlspecialchars($_GET[orderflag]);	
		$order =htmlspecialchars($_GET[orderflag]);
		$kaishi=htmlspecialchars($_GET[fidx]);
		$jieshu=htmlspecialchars($_GET[eidx]);
		$p =$kaishi;	
		$sun_cate = $this->db->Ylist("SELECT cateid from `@#_zg_fenlei` where `parentid` = '$cate_band'");
		foreach($sun_cate as $v){
			$sun_id_str .= "'".$v['cateid']."'".",";
			//var_dump($sun_id_str);
		}		
		$newstr = substr($sun_id_str,0,strlen($sun_id_str)-1);
		if($newstr){
		if(!$select){
			$select = '10';
		}		
		if($cate_band){
			$fen1 = intval($cate_band);	
			$cate_band = 'list';			
		}
		//var_dump($fen1);
		if(empty($fen1)){
			$pinpai=$this->db->Ylist("select * from `@#_zg_pinpai` where 1 order by `order` DESC");	
			$daohangs = '所有分类';	
		}else{
			$pinpai=$this->db->Ylist("select * from `@#_zg_pinpai` where `cateid`='$fen1' order by `order` DESC");
			$daohangs=$this->db->YOne("select * from `@#_zg_fenlei` where `cateid` = '$fen1' order by `order` DESC");			
			$daohangs = $daohangs['name'];			
		}	
			
		$fenlei=$this->db->Ylist("select * from `@#_zg_fenlei` where `model` = '1'");
		

		//

		
		//分页
		
		$end=$jieshu;
		
		//var_dump($end);
		$star=($p-1);
		//var_dump($star);
		$select_w = '';
		if($select == 10){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 20){
			$select_w = "and `renqi` = '1'";
		}
		if($select == 30){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 40){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 30){
			$select_w = 'order by `money` DESC';
		}
		if($select == 31){
			$select_w = 'order by `money` ASC';
		}
		if($select == 50){
			$select_w = 'order by `id` DESC';
		}
		if($select == 60){
			$select_w = 'order by `money` ASC';
		}

			//var_dump($newstr);	 
		if($fen1){		
			$count=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and uid = 0 and `q_uid` is null and `cateid` in ($newstr) $select_w");
		}else{			
			$count=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and uid = 0 and  `q_uid` is null $select_w");
		}
		if($fen1){
			
			$yyslist=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and uid = 0 and  `q_uid` is null and `cateid` in ($newstr) $select_w limit $star,$end");
		
		}else{	
			
			$yyslist=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and uid = 0 and  `q_uid` is null $select_w limit $star,$end");
		} 
		}
		//var_dump(count($yyslist));
		
		
		//var_dump($yyslist);
		if($yyslist){
		$yyslist1['code']=0;
		$yyslist1['count']=count($count);
		foreach($yyslist as $key=>$val){
			$yyslist1['listItems'][$key]['rowid']=0;
			$yyslist1['listItems'][$key]['goodsid']=$val['id'];
			$yyslist1['listItems'][$key]['goodssnme']=$val['title'];
			$yyslist1['listItems'][$key]['goodspic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
			$yyslist1['listItems'][$key]['codeid']=$val['id'];
			$yyslist1['listItems'][$key]['codeprice']=$val['money'];
			$yyslist1['listItems'][$key]['codequantity']=$val['zongrenshu'];
			$yyslist1['listItems'][$key]['codesales']=$val['canyurenshu'];
			$yyslist1['listItems'][$key]['codeperiod']=$val['qishu'];
			$yyslist1['listItems'][$key]['codetype']=0;
			$yyslist1['listItems'][$key]['goodstag']=0;
			$yyslist1['listItems'][$key]['codelimitbuy']=0;
			$yyslist1['listItems'][$key]['maxqishu']=$val['maxqishu'];
			$yyslist1['listItems'][$key]['expressFee']= sprintf("%.2f", $val['expressFee']);
			$yyslist1['listItems'][$key]['yunjiage']= sprintf("%.2f", $val['yunjiage']);
		}
		
		
	}
	else{
			$yyslist1['code']=1;
		}
	echo json_encode($yyslist1);
}
//直购商品列表end

//活动商品专区开始20161008
public function getGoodsPageListhd(){
	$_GET = array_change_key_case($_GET, CASE_LOWER);
	    $webname=$this->_yys['web_name'];
		$cate_band =htmlspecialchars($_GET[sortid]);
		//var_dump($cate_band);
		$select =htmlspecialchars($_GET[orderflag]);	
		$order =htmlspecialchars($_GET[orderflag]);
		$kaishi=htmlspecialchars($_GET[fidx]);
		$jieshu=htmlspecialchars($_GET[eidx]);
		$p =$kaishi;	
		$sun_cate = $this->db->Ylist("SELECT cateid from `@#_zg_fenlei` where `parentid` = '$cate_band'");
		foreach($sun_cate as $v){
			$sun_id_str .= "'".$v['cateid']."'".",";
			//var_dump($sun_id_str);
		}		
		$newstr = substr($sun_id_str,0,strlen($sun_id_str)-1);
		if($newstr){
		if(!$select){
			$select = '10';
		}		
		if($cate_band){
			$fen1 = intval($cate_band);	
			$cate_band = 'list';			
		}
		//var_dump($fen1);
		if(empty($fen1)){
			$pinpai=$this->db->Ylist("select * from `@#_zg_pinpai` where 1 order by `order` DESC");	
			$daohangs = '所有分类';	
		}else{
			$pinpai=$this->db->Ylist("select * from `@#_zg_pinpai` where `cateid`='$fen1' order by `order` DESC");
			$daohangs=$this->db->YOne("select * from `@#_zg_fenlei` where `cateid` = '$fen1' order by `order` DESC");			
			$daohangs = $daohangs['name'];			
		}	
			
		$fenlei=$this->db->Ylist("select * from `@#_zg_fenlei` where `model` = '1'");
		

		//

		
		//分页
		
		$end=$jieshu;
		
		//var_dump($end);
		$star=($p-1);
		//var_dump($star);
		$select_w = '';
		if($select == 10){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 20){
			$select_w = "and `renqi` = '1'";
		}
		if($select == 30){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 40){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 30){
			$select_w = 'order by `money` DESC';
		}
		if($select == 31){
			$select_w = 'order by `money` ASC';
		}
		if($select == 50){
			$select_w = 'order by `id` DESC';
		}
		if($select == 60){
			$select_w = 'order by `money` ASC';
		}

			//var_dump($newstr);	 
		if($fen1){		
			$count=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and cashback > 1 and `isshelve`='0' and `q_uid` is null and `cateid` in ($newstr) $select_w");
		}else{			
			$count=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and cashback > 1 and `isshelve`='0' and  `q_uid` is null $select_w");
		}
		if($fen1){
			
			$yyslist=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and cashback > 1 and `isshelve`='0' and  `q_uid` is null and `cateid` in ($newstr) $select_w limit $star,$end");
		
		}else{	
			
			$yyslist=$this->db->Ylist("select * from `@#_zg_shangpin` where `maxqishu` > 0 and cashback > 1 and `isshelve`='0' and  `q_uid` is null $select_w limit $star,$end");
		} 
		}
		//var_dump(count($yyslist));
		
		
		//var_dump($yyslist);
		if($yyslist){
		$yyslist1['code']=0;
		$yyslist1['count']=count($count);
		foreach($yyslist as $key=>$val){
			$yyslist1['listItems'][$key]['rowid']=0;
			$yyslist1['listItems'][$key]['goodsid']=$val['id'];
			$yyslist1['listItems'][$key]['goodssnme']=$val['title'];
			$yyslist1['listItems'][$key]['goodspic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
			$yyslist1['listItems'][$key]['codeid']=$val['id'];
			$yyslist1['listItems'][$key]['codeprice']=$val['money'];
			$yyslist1['listItems'][$key]['codequantity']=$val['zongrenshu'];
			$yyslist1['listItems'][$key]['codesales']=$val['canyurenshu'];
			$yyslist1['listItems'][$key]['codeperiod']=$val['qishu'];
			$yyslist1['listItems'][$key]['codetype']=0;
			$yyslist1['listItems'][$key]['goodstag']=0;
			$yyslist1['listItems'][$key]['codelimitbuy']=0;
			$yyslist1['listItems'][$key]['maxqishu']=$val['maxqishu'];
			$yyslist1['listItems'][$key]['expressFee']= sprintf("%.2f", $val['expressFee']);
			$yyslist1['listItems'][$key]['yunjiage']= sprintf("%.2f", $val['yunjiage']);
		}
		
		
	}
	else{
			$yyslist1['code']=1;
		}
	echo json_encode($yyslist1);
}
//活动商品专区结束20161008
//直购购物车
    //购物车数量
	public function cartnumzg(){	  
	  $Mcartlist=$this->Mcartlist;
	  if(is_array($Mcartlist)){
	  	  $gouwuchenum['code']=0;
	      $gouwuchenum['num']=count($Mcartlist);	  
	  }else{
	  	  $gouwuchenum['code']=1;
	      $gouwuchenum['num']=0;	  
	  }
      //var_dump($Mcartlist);
	  echo json_encode($gouwuchenum);
	}
	
	//添加购物车
	public function addShopCartzg(){
		$_GET = array_change_key_case($_GET, CASE_LOWER);
		$ShopId=safe_replace($this->segment(4));
		$shopnum=safe_replace($this->segment(5));
		$subType = str_replace('\\','',$_GET['subtype']);

		$Mcartlist = $this->Cartlistzg;

		/*处理+-*/
		if($Mcartlist[$ShopId]){
			$subType = $Mcartlist[$ShopId]['subType'];
		}
		if(empty($ShopId)){
			$ShopId=htmlspecialchars($_GET[codeid]);
		}
		if(empty($shopnum)){
			$shopnum=htmlspecialchars($_GET[shopnum]);
		}
		
		$gouwuchebs=safe_replace($this->segment(6));//标识从哪里加的购物车
		$shopis=0;          //0表示不存在  1表示存在

		if($ShopId == 0 || $shopnum == 0){
			$gouwuche['code']=1;   //表示添加失败
		}else{
			if(is_array($Mcartlist)){
				foreach($Mcartlist as $key=>$val){
					$newKey = explode('_',$key);
					$newShopId = explode('_',$ShopId);
					if($newKey['0'] == $ShopId['0'] && $val['subType'] == $subType){
						if(isset($gouwuchebs) && $gouwuchebs=='cartzg'){
							$Mcartlist[$ShopId]['num'] = $shopnum;
							$Mcartlist[$ShopId]['subType'] = $subType;
						}else{
							$Mcartlist[$ShopId]['num'] = $val['num']+$shopnum;
							$Mcartlist[$ShopId]['subType'] = $subType;
						}
						$shopis=1;
					}else{
						$Mcartlist[$key]['num'] = 1;
						$Mcartlist[$ShopId]['subType'] = $subType;
					}
				}
			}else{
				$Mcartlist =array();		  
				$Mcartlist[$ShopId]['num']=$shopnum; 
				$Mcartlist[$ShopId]['subType'] = $subType;
			}
        
			if($shopis==0){
				$Mcartlist[$ShopId]['num']=$shopnum;
				$Mcartlist[$ShopId]['subType'] = $subType;
			}
		   
			_setcookie('Cartlistzg',json_encode($Mcartlist),'');   
			$gouwuche['code']=0;   //表示添加成
		}
	
		$gouwuche['num']=count($Mcartlist);    //表示现在购物车有多少条记录
		echo json_encode($gouwuche);
	}
	
	public function delCartItemzg(){
		$ShopId = safe_replace($this->segment(4));
		$gouwuchelist = $this->Cartlistzg;

		if($ShopId == 0){
			$gouwuche['code']=1;   //删除失败
		}else{ 
		   if(is_array($gouwuchelist)){
				if(count($gouwuchelist)==1){
					foreach($gouwuchelist as $key=>$val){
						if($key == $ShopId){		
							$gouwuche['code']=0;	
							_setcookie('Cartlistzg','','');
						}else{
							$gouwuche['code']=1;	
						}
					}
				}else{
				   foreach($gouwuchelist as $key=>$val){
						if($key == $ShopId){						  	
							$gouwuche['code']=0;							  
						}else{
							$Mcartlist[$key]['num'] = $val['num'];
						}
					}
					_setcookie('Cartlistzg',json_encode($Mcartlist),'');   
				}
			}else{
			   $gouwuche['code']=1;   //删除失败
			}
		}		
		echo json_encode($gouwuche);	
	}
	
//直购商品列表end
//10yuanqu
public function getGoodsPageList10(){
	$_GET = array_change_key_case($_GET, CASE_LOWER);
	    $webname=$this->_yys['web_name'];
		$cate_band =htmlspecialchars($_GET[sortid]);
		//var_dump($cate_band);
		$select =htmlspecialchars($_GET[orderflag]);	
		$order =htmlspecialchars($_GET[orderflag]);
	$kaishi=htmlspecialchars($_GET[fidx]);
	$jieshu=htmlspecialchars($_GET[eidx]);
		$p =$kaishi;	
		
		

		$sun_cate = $this->db->Ylist("SELECT cateid from `@#_fenlei` where `parentid` = '$cate_band'");
		
				foreach($sun_cate as $v){
					$sun_id_str .= "'".$v['cateid']."'".",";
					//var_dump($sun_id_str);
				}		
				$newstr = substr($sun_id_str,0,strlen($sun_id_str)-1);
		if($newstr){
		if(!$select){
			$select = '10';
		}		
		if($cate_band){
			$fen1 = intval($cate_band);	
			$cate_band = 'list';			
		}
		//var_dump($fen1);
		if(empty($fen1)){
			$pinpai=$this->db->Ylist("select * from `@#_pinpai` where 1 order by `order` DESC");	
			$daohangs = '所有分类';	
		}else{
			$pinpai=$this->db->Ylist("select * from `@#_pinpai` where `cateid`='$fen1' order by `order` DESC");
			$daohangs=$this->db->YOne("select * from `@#_fenlei` where `cateid` = '$fen1' order by `order` DESC");			
			$daohangs = $daohangs['name'];			
		}	
			
		$fenlei=$this->db->Ylist("select * from `@#_fenlei` where `model` = '1'");
		

		//

		
		//分页
		
		$end=$jieshu;
		
		//var_dump($end);
		$star=($p-1);
		//var_dump($star);
		$select_w = '';
		if($select == 10){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 20){
			$select_w = "and `renqi` = '1'";
		}
		if($select == 30){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 40){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 30){
			$select_w = 'order by `money` DESC';
		}
		if($select == 31){
			$select_w = 'order by `money` ASC';
		}
		if($select == 50){
			$select_w = 'order by `id` DESC';
		}
		if($select == 60){
			$select_w = 'order by `money` ASC';
		}

			//var_dump($newstr);	 
		if($fen1){		
			$count=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null and `yunjiage`=10 and `cateid` in ($newstr) $select_w");
		}else{			
			$count=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null and `yunjiage`=10 $select_w");
		}
		if($fen1){
			
			$yyslist=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null and `yunjiage`=10 and `cateid` in ($newstr) $select_w limit $star,$end");
		
		}else{	
			
			$yyslist=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null and `yunjiage`=10 $select_w limit $star,$end");
		} 
		}
		//var_dump(count($yyslist));
		
		
		//var_dump($yyslist);
		if($yyslist){
		$yyslist1['code']=0;
		$yyslist1['count']=count($count);
		foreach($yyslist as $key=>$val){
			
$yyslist1['listItems'][$key]['rowid']=0;
$yyslist1['listItems'][$key]['goodsid']=$val['id'];
$yyslist1['listItems'][$key]['goodssnme']=$val['title'];
$yyslist1['listItems'][$key]['goodspic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
$yyslist1['listItems'][$key]['codeid']=$val['id'];
$yyslist1['listItems'][$key]['codeprice']=$val['money'];
$yyslist1['listItems'][$key]['codequantity']=$val['zongrenshu'];
$yyslist1['listItems'][$key]['codesales']=$val['canyurenshu'];
$yyslist1['listItems'][$key]['codeperiod']=$val['qishu'];
$yyslist1['listItems'][$key]['codetype']=0;
$yyslist1['listItems'][$key]['goodstag']=0;
$yyslist1['listItems'][$key]['codelimitbuy']=0;
		}
		
		
	}
	else{
			$yyslist1['code']=1;
		}
	echo json_encode($yyslist1);
}
//百云区

//10yuanqu
public function getGoodsPageList100(){
	$_GET = array_change_key_case($_GET, CASE_LOWER);
	    $webname=$this->_yys['web_name'];
		$cate_band =htmlspecialchars($_GET[sortid]);
		//var_dump($cate_band);
		$select =htmlspecialchars($_GET[orderflag]);	
		$order =htmlspecialchars($_GET[orderflag]);
	$kaishi=htmlspecialchars($_GET[fidx]);
	$jieshu=htmlspecialchars($_GET[eidx]);
		$p =$kaishi;	
		
		

		$sun_cate = $this->db->Ylist("SELECT cateid from `@#_fenlei` where `parentid` = '$cate_band'");
		
				foreach($sun_cate as $v){
					$sun_id_str .= "'".$v['cateid']."'".",";
					//var_dump($sun_id_str);
				}		
				$newstr = substr($sun_id_str,0,strlen($sun_id_str)-1);
		if($newstr){
		if(!$select){
			$select = '10';
		}		
		if($cate_band){
			$fen1 = intval($cate_band);	
			$cate_band = 'list';			
		}
		//var_dump($fen1);
		if(empty($fen1)){
			$pinpai=$this->db->Ylist("select * from `@#_pinpai` where 1 order by `order` DESC");	
			$daohangs = '所有分类';	
		}else{
			$pinpai=$this->db->Ylist("select * from `@#_pinpai` where `cateid`='$fen1' order by `order` DESC");
			$daohangs=$this->db->YOne("select * from `@#_fenlei` where `cateid` = '$fen1' order by `order` DESC");			
			$daohangs = $daohangs['name'];			
		}	
			
		$fenlei=$this->db->Ylist("select * from `@#_fenlei` where `model` = '1'");
		

		//

		
		//分页
		
		$end=$jieshu;
		
		//var_dump($end);
		$star=($p-1);
		//var_dump($star);
		$select_w = '';
		if($select == 10){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 20){
			$select_w = "and `renqi` = '1'";
		}
		if($select == 30){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 40){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 30){
			$select_w = 'order by `money` DESC';
		}
		if($select == 31){
			$select_w = 'order by `money` ASC';
		}
		if($select == 50){
			$select_w = 'order by `id` DESC';
		}
		if($select == 60){
			$select_w = 'order by `money` ASC';
		}

			//var_dump($newstr);	 
		if($fen1){		
			$count=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null and `yunjiage`=100 and `cateid` in ($newstr) $select_w");
		}else{			
			$count=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null and `yunjiage`=100 $select_w");
		}
		if($fen1){
			
			$yyslist=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null and `yunjiage`=100 and `cateid` in ($newstr) $select_w limit $star,$end");
		
		}else{	
			
			$yyslist=$this->db->Ylist("select id,title,thumb,qishu,money,zongrenshu,canyurenshu,qishu from `@#_shangpin` where uid = 0 and  `q_uid` is null and `yunjiage`=100 $select_w limit $star,$end");
		} 
		}
		//var_dump(count($yyslist));
		
		
		//var_dump($yyslist);
		if($yyslist){
		$yyslist1['code']=0;
		$yyslist1['count']=count($count);
		foreach($yyslist as $key=>$val){
			
$yyslist1['listItems'][$key]['rowid']=0;
$yyslist1['listItems'][$key]['goodsid']=$val['id'];
$yyslist1['listItems'][$key]['goodssnme']=$val['title'];
$yyslist1['listItems'][$key]['goodspic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
$yyslist1['listItems'][$key]['codeid']=$val['id'];
$yyslist1['listItems'][$key]['codeprice']=$val['money'];
$yyslist1['listItems'][$key]['codequantity']=$val['zongrenshu'];
$yyslist1['listItems'][$key]['codesales']=$val['canyurenshu'];
$yyslist1['listItems'][$key]['codeperiod']=$val['qishu'];
$yyslist1['listItems'][$key]['codetype']=0;
$yyslist1['listItems'][$key]['goodstag']=0;
$yyslist1['listItems'][$key]['codelimitbuy']=0;
		}
		
		
	}
	else{
			$yyslist1['code']=1;
		}
	echo json_encode($yyslist1);
}

//佣金提交
public function memberCenterApplyToBank(){
	$huiyuan=$this->userinfo;

$money=htmlspecialchars($_GET['money']);
$userName=htmlspecialchars($_GET['userName']);
$bankName=htmlspecialchars($_GET['bankName']);
$subBank=htmlspecialchars($_GET['subBank']);
$bankNo=htmlspecialchars($_GET['bankNo']);
$phone=htmlspecialchars($_GET['phone']);
$cha=$this->db->YOne("select * from `@#_yonghu` where uid='$huiyuan[uid]'");
$ye=$this->db->YOne("select yongjin from `@#_yonghu` where `uid`='$huiyuan[uid]' limit 1"); 
$time=time();
        $cashouthdtotal= $ye[yongjin];  //佣金惠券币
$uid=$huiyuan[uid];
 if($money<100){
               $yys[code]=-1;
            }elseif($cashouthdtotal<$money){
                $yys[code]=0;
            }else{

                //插入提现申请表  这里不用在佣金表中插入记录 等后台审核才插入
                $mrecode1=$this->db->Query("INSERT INTO `@#_yonghu_cashout`(`uid`,`money`,`username`,`bankname`,`branch`,`banknumber`,`linkphone`,`time`)VALUES
			('$uid','$money','$userName','$bankName','$subBank','$bankNo','$phone','$time')");
$gg="INSERT INTO `@#_yonghu_cashout`(`uid`,`money`,`username`,`bankname`,`branch`,`banknumber`,`linkphone`,`time`)VALUES
			('$uid','$money','$userName','$bankName','$subBank','$bankNo','$phone','$time')";
			 $leavemoney=$huiyuan['money']+$money;
			 $yongjins=$huiyuan['yongjin']-$money;
// $mrecode2=$this->db->Query("UPDATE `@#_yonghu` SET `money`='$leavemoney',`yongjin`='$yongjins' WHERE `uid`='$uid' ");
 $mrecode2 = $this->db->Query("UPDATE `@#_yonghu` SET `yongjin`='$yongjins' WHERE `uid`='$uid' ");
if($mrecode1&&$mrecode2){

                $yys[code]=1;
}
            }



echo json_encode($yys);

}
//修改密码

public function updateUserPwd(){
$huiyuan=$this->userinfo;

$oldpass=htmlspecialchars($_GET['userOldPwd']);
$newpass=md5(htmlspecialchars($_GET['userNewPwd']));
$cha=$this->db->YOne("select * from `@#_yonghu` where uid='$huiyuan[uid]'");




if($cha['password']==md5($oldpass)){
	$password=$this->db->Query("UPDATE `@#_yonghu` SET password='$newpass' where uid='$huiyuan[uid]'");
$yys[code]=0;
_setcookie("uid","",time()-3600);
		_setcookie("ushell","",time()-3600);
}else if($cha['password']!=md5($oldpass)){
$yys[code]=1;
}else{
$yys[code]=5;
}

echo json_encode($yys);
}

//转到惠券币
//转到惠券币
public function memberCenterApplyToAccount(){
$huiyuan=$this->userinfo;
	//$fufen = System::DOWN_App_config("user_fufen",'','member');	
$zhuanru=$this->db->Query("UPDATE `@#_yonghu` SET yongjin=yongjin-floor($huiyuan[yongjin]),money=money+floor($huiyuan[yongjin]) where uid='$huiyuan[uid]'");

            $type       = 1;
            $pay        ="佣金";
            $time       =time();
            $content    ="使用佣金充值到汇格同城账户";

            $account=$this->db->Query("INSERT INTO `@#_yonghu_zhanghao`(`uid`,`type`,`pay`,`content`,`money`,`time`)VALUES
			('$huiyuan[uid]','$type','$pay','$content','$huiyuan[yongjin]','$time')");
if($zhuanru&&$account){
$yys[code]=0;
$yys[money]=floor($huiyuan[yongjin]);
}else{
$yys[code]=10;
}
echo json_encode($yys);
}
//购买记录json
	public function goumaijilu(){
		$_GET = array_change_key_case($_GET, CASE_LOWER);
		$fidx=htmlspecialchars($_GET[fidx])-1;
	   $eidx=htmlspecialchars($_GET[eidx]);
	   $xiangmuid=htmlspecialchars($_GET[codeid]);
	 //  $isCount=$this->segment(6);
		$goumaijilu=$this->db->Ylist("select * from `@#_yonghu_yys_record` where `shopid`='$xiangmuid' order by time desc limit $fidx,$eidx");
		$count=$this->db->Ylist("select id from `@#_yonghu_yys_record` where `shopid`='$xiangmuid' order by time desc");
		if(empty($goumaijilu)){
			$yyslist['Code']=1;
		}else{
		$yyslist['Code']=0;
		$yyslist['Count']=count($count);
		foreach($goumaijilu as $key=>$val){
			
$yyslist['Data']['Tables']['BuyList']['Rows'][$key]['username']=$val['username'];
$yyslist['Data']['Tables']['BuyList']['Rows'][$key]['userphoto']=$val['uphoto'];
$yyslist['Data']['Tables']['BuyList']['Rows'][$key]['userweb']=$val['uid'];
$yyslist['Data']['Tables']['BuyList']['Rows'][$key]['buynum']=$val['gonumber'];
$yyslist['Data']['Tables']['BuyList']['Rows'][$key]['buyip']=$val['ip'];
$yyslist['Data']['Tables']['BuyList']['Rows'][$key]['buyipaddr']=5;
$yyslist['Data']['Tables']['BuyList']['Rows'][$key]['buytime']=microt($val['time']);
$yyslist['Data']['Tables']['BuyList']['Rows'][$key]['buydevice']=6;
$yyslist['Data']['Tables']['BuyList']['Rows'][$key]['buyid']=$val['shopid'];


		 }   
		}
	   // $webname=$this->_yys['web_name'];
		//$key="所有汇格同城记录";
	//	$xiangmuid=intval($this->segment(4));
		//$cords=$this->db->Ylist("select * from `@#_yonghu_yys_record` where `shopid`='$xiangmuid' order by time desc");
		//if(!$cords){
			//_notemobilemobile('还没有购买记录!');
		//}
		echo json_encode($yyslist);
	
	
	}




	//购买记录json
	public function more(){
		//ini_set("display_errors", "On");

//error_reporting(E_ALL | E_STRICT);
		$fidx=htmlspecialchars($_GET['FIdx'])-1;
	   $eidx=htmlspecialchars($_GET['EIdx']);
	   $xiangmuid=htmlspecialchars($_GET['goodsID']);
		
		//新加补丁
		$xiangmu = $this->db->YOne("select * from `@#_shangpin` where `id`='$xiangmuid' LIMIT 1");

		//$yys_record_list = $this->db->Ylist("select * from `@#_yonghu_yys_record` where `shopid` = '$xiangmu[id]' and `shopqishu` = '$xiangmu[qishu]' order by `id` DESC limit 50");
		
		$xiangmuzx = $this->db->YOne("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' and `qishu`>'$xiangmu[qishu]' order by `qishu` DESC LIMIT 1");
		
		//期数显示
		$xiangmulist = $this->db->Ylist("select id,sid,cateid,brandid,title,title,title2,keywords,description,money,yunjiage,zongrenshu,canyurenshu,shenyurenshu,def_renshu,qishu,maxqishu,thumb,picarr,codes_table,xsjx_time,pos,renqi,time,q_uid,q_user,q_user_code,q_content,q_counttime,q_end_time,q_showtime,renqi1,ka,mi,ex_yuedingzhongjiang,cardId,cardPwd,cardId1,leixing,yuanjia,q_end_cp,fahuo from `@#_shangpin` where `sid`='$xiangmu[sid]' order by `qishu` DESC limit $fidx,$eidx");
		$count = $this->db->Ylist("select id from `@#_shangpin` where `sid`='$xiangmu[sid]' order by `qishu` DESC");
		
		//var_dump($xiangmulist);
		//$xiangmulists = $this->db->Ylist("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' order by `qishu` DESC");


		
		
		if(empty($xiangmulist)){
			$yyslist['Code']=1;
		}else{
		$yyslist['code']=0;
		$yyslist['count']=count($count);
		$yyslist['minPeriod']=$xiangmulist['0']['qishu'];
		$yyslist['newPeriod']=$xiangmuzx['qishu'];
		$yyslist['newCodeID']=$xiangmuzx['id'];
		foreach($xiangmulist as $key=>$val){
			if(!empty($val[id])){
				$goods=$this->db->YOne("select * from `@#_yonghu_yys_record` where `shopid`=$val[id] and `huode` > 0");
			}
if($val['q_end_time']!=''&&$val['q_showtime']!='Y'){
			   //商品已揭晓
			    $yyslist['listItems'][$key]['codeState']=3;

			   
			 }elseif($val['shenyurenshu']==0){
			 //商品购买次数已满
			   $yyslist['listItems'][$key]['codeState']=2;

			 }else{
			 //进行中
			    $yyslist['listItems'][$key]['codeState']=1;
				 
			 }

$yyslist['listItems'][$key]['codeID']=$val['id'];

$yyslist['listItems'][$key]['userPhoto']=$goods['uphoto'];

$yyslist['listItems'][$key]['userName']=$goods['username'];


$yyslist['listItems'][$key]['buyNum']=$goods['gonumber'];
$yyslist['listItems'][$key]['codeRNO']=$val['q_user_code'];
$yyslist['listItems'][$key]['codeRTime']=microt($val['q_end_time']);
$yyslist['listItems'][$key]['userWeb']=$goods['uid'];
$yyslist['listItems'][$key]['codePeriod']=$val['qishu'];
$yyslist['listItems'][$key]['codeQuantity']=$val['zongrenshu'];
$yyslist['listItems'][$key]['codeSales']=$val['canyurenshu'];
$yyslist['listItems'][$key]['goodsPic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];


		 }   
		}

		echo json_encode($yyslist);
	
	
	}
    public function getMemberCenterUserWinList(){
    $_GET = array_change_key_case($_GET, CASE_LOWER);
    $fidx=htmlspecialchars($_GET[fidx])-1;
    $eidx=htmlspecialchars($_GET[eidx]);
    $xiangmuid=htmlspecialchars($_GET[codeid]);
    $huiyuan=$this->userinfo;
    $uid = $huiyuan['uid'];
    $orderlist['listItems']=$this->db->Ylist("select id,sid,cateid,brandid,title,title,title2,keywords,description,money,yunjiage,zongrenshu,canyurenshu,shenyurenshu,def_renshu,qishu,maxqishu,thumb,picarr,codes_table,xsjx_time,pos,renqi,time,q_uid,q_user,q_user_code,q_content,q_counttime,q_end_time,q_showtime,renqi1,ka,mi,ex_yuedingzhongjiang,cardId,cardPwd,cardId1,leixing,yuanjia,q_end_cp,fahuo from `@#_shangpin` where q_uid='$huiyuan[uid]' and q_showtime!='Y' ORDER BY q_end_time DESC limit $fidx,$eidx " );

    if(!$orderlist['listItems']){
        $yyslist['code']=-1;
        $yyslist['tips']="暂无记录";
    }else{
        $yyslist['code']=0;
        $yyslist['totalCount']=count($orderlist['listItems']);
        foreach($orderlist['listItems'] as $key=>$val){
            $shopshop = $this->db->YOne("select uid,shopid,status,id,company_code,company from `@#_yonghu_yys_record` where `shopid`='$val[id]' and `shopqishu`='$val[qishu]' and `uid`='$huiyuan[uid]' and `huode`>'10000000' order by id desc");


            $shaidanyn=$this->db->YOne("select sd_id from `@#_shai` where `sd_shopid`='$shopshop[shopid]' and `sd_userid` = '$shopshop[uid]'");

            $status=@explode(",",$shopshop['status']);
            //var_dump($status[3].'ID号'.$shopshop['shopid']);
            if($status[3]=='未提交地址'){
                $yyslist['listItems'][$key]['status']=0;
            }else if ($status[3]=='已提交地址'){
                if($status[1]=='未发货'){
                    $yyslist['listItems'][$key]['status']=1;
                }
            }else if($status[1]=='已发货'&&$status[2]!='已完成'&&$status[2]!='已作废'){
                $yyslist['listItems'][$key]['status']=2;
            }else if($status[1]=='已发货'&&$status[2]!='未完成'&&$status[2]!='已作废'){
                $yyslist['listItems'][$key]['status']=3;
                if(empty($shaidanyn)){
                    $yyslist['listItems'][$key]['status']=4;
                }
            }else if($status[2]=='已作废'){
                $yyslist['listItems'][$key]['status']=4;
            }
            $yyslist['listItems'][$key]['codeID'] = $val['id'];

            $yyslist['listItems'][$key]['codeIDs']=$val['id'];
            $yyslist['listItems'][$key]['goodsPic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
            $yyslist['listItems'][$key]['goodsName']=$val['title'];
            $yyslist['listItems'][$key]['codeRNO']=$val['q_user_code'];
            $yyslist['listItems'][$key]['codeRTime']=microt($val['q_end_time']);
            $yyslist['listItems'][$key]['orderState']=$yyslist['listItems'][$key]['status'];
            $yyslist['listItems'][$key]['orderNo']=$shopshop['id'];
            $yyslist['listItems'][$key]['codePeriod']=$val['qishu'];
            if(empty($shaidanyn)){
                $yyslist['listItems'][$key]['IsPostSingle']=1;
            }else{
                $yyslist['listItems'][$key]['IsPostSingle']=0;
            }
            $yyslist['listItems'][$key]['yuanjia']=$val['yuanjia'];
            $yyslist['listItems'][$key]['codePrice']=$val['money'];
            $yyslist['listItems'][$key]['codeType']=$val['shopid'];
            $yyslist['listItems'][$key]['orderActDesc']=$val['shopid'];
            $yyslist['listItems'][$key]['orderAddTime']=$val['shopid'];
            $yyslist['listItems'][$key]['actAddTime']=$val['shopid'];
            $yyslist['listItems'][$key]['goodsID']=$val['id'];
            $yyslist['listItems'][$key]['buyNum']=$val['shopid'];
            $yyslist['listItems'][$key]['orderType']=0;
            $yyslist['listItems'][$key]['ordersaleprice']=$val['money'];
            $yyslist['listItems'][$key]['company_code']=$shopshop['company_code'];
            $yyslist['listItems'][$key]['leixing']=$val['leixing'];
            $yyslist['listItems'][$key]['ka']=$val['cardId'];
            $yyslist['listItems'][$key]['mi']=$val['cardPwd'];
            $yyslist['listItems'][$key]['company']=$shopshop['company'];
            $yyslist['listItems'][$key]['shaidan']=$shaidanyn;
			$yyslist['listItems'][$key]['uid']=$shopshop['uid'];

        }
    }
    echo json_encode($yyslist);


}
//直购开始
public function getMemberCenterUserWinListzg(){
    $_GET = array_change_key_case($_GET, CASE_LOWER);
    $fidx=htmlspecialchars($_GET[fidx])-1;
    $eidx=htmlspecialchars($_GET[eidx]);
    $xiangmuid=htmlspecialchars($_GET[codeid]);
    $huiyuan=$this->userinfo;
    $uid = $huiyuan['uid'];
    $orderlist['listItems']=$this->db->Ylist("select * from `@#_zg_yonghu_yys_record` where `uid`='$huiyuan[uid]' and `goucode`='zg' ORDER BY id DESC limit $fidx,$eidx " );
    if(!$orderlist['listItems']){
        $yyslist['code']=-1;
        $yyslist['tips']="暂无记录";
    }else{
        $yyslist['code']=0;
        $yyslist['totalCount']=count($orderlist['listItems']);
        foreach($orderlist['listItems'] as $key=>$val){
            $shopshop=$this->db->YOne("select * from `@#_zg_shangpin` where `id`='$val[shopid]'");

            $shaidanyn=$this->db->YOne("select sd_id from `@#_shai` where `sd_shopid`='$shopshop[shopid]' and `sd_userid` = '$shopshop[uid]'");

            $status=@explode(",",$val['status']);
            //var_dump($status[3].'ID号'.$shopshop['shopid']);
            if($status[3]=='未提交地址'){
                $yyslist['listItems'][$key]['status']=0;
            }else if ($status[3]=='已提交地址'){
                if($status[1]=='未发货'){
                    $yyslist['listItems'][$key]['status']=1;
                }
            }else if($status[1]=='已发货'&&$status[2]!='已完成'&&$status[2]!='已作废'){
                $yyslist['listItems'][$key]['status']=2;
            }else if($status[1]=='已发货'&&$status[2]!='未完成'&&$status[2]!='已作废'){
                $yyslist['listItems'][$key]['status']=3;
                if(empty($shaidanyn)){
                    $yyslist['listItems'][$key]['status']=4;
                }
            }else if($status[2]=='已作废'){
                $yyslist['listItems'][$key]['status']=4;
            }
            $yyslist['listItems'][$key]['codeID']=$val['id'];

            $yyslist['listItems'][$key]['codeIDs']=$val['id'];
            $yyslist['listItems'][$key]['goodsPic']=YYS_LOCAL_PATH."/statics/uploads/".$shopshop['thumb'];
            $yyslist['listItems'][$key]['goodsName']=$shopshop['title'];
            $yyslist['listItems'][$key]['codeRNO']=$val['q_user_code'];
            $yyslist['listItems'][$key]['codeRTime'] = microt($val['time']);
            $yyslist['listItems'][$key]['orderState']=$yyslist['listItems'][$key]['status'];
            $yyslist['listItems'][$key]['orderNo']=$val['id'];
			$yyslist['listItems'][$key]['orderCode']=$val['code'];
            $yyslist['listItems'][$key]['codePeriod']=$val['qishu'];
            if(empty($shaidanyn)){
                $yyslist['listItems'][$key]['IsPostSingle']=1;
            }else{
                $yyslist['listItems'][$key]['IsPostSingle']=0;
            }
            $yyslist['listItems'][$key]['yuanjia']=$val['yuanjia'];
            $yyslist['listItems'][$key]['codePrice']=$val['money'];
            $yyslist['listItems'][$key]['codeType']=$val['shopid'];
            $yyslist['listItems'][$key]['orderActDesc']=$val['shopid'];
            $yyslist['listItems'][$key]['orderAddTime']=$val['shopid'];
            $yyslist['listItems'][$key]['actAddTime']=$val['shopid'];
            $yyslist['listItems'][$key]['goodsID']=$val['id'];
            $yyslist['listItems'][$key]['buyNum']=$val['shopid'];
            $yyslist['listItems'][$key]['orderType']=0;
            $yyslist['listItems'][$key]['ordersaleprice']=$val['money'];
            $yyslist['listItems'][$key]['company_code']=$val['company_code'];
            $yyslist['listItems'][$key]['leixing']=$val['leixing'];
            $yyslist['listItems'][$key]['ka']=$val['cardId'];
            $yyslist['listItems'][$key]['mi']=$val['cardPwd'];
            $yyslist['listItems'][$key]['company']=$val['company'];
            $yyslist['listItems'][$key]['shaidan']=$shaidanyn;
			
			
			$img = $this->db->YOne("select * from `@#_zg_shangpin` where `id` = '$one[shopid]'");
			$yyslist['listItems'][$key]['thumb'] = $img['thumb'];
			
			if($val['newTypes']){
				$newTypes = json_decode($val['newTypes'],true);
				$html = '';
				foreach($newTypes as $k => $o){
					$html .= '<br/>'.$o['bigName'].'：'.$o['name'].'，价格：'.$o['price'];
				}
				$yyslist['listItems'][$key]['type'] = $html;
			}
			
        }
    }

    echo json_encode($yyslist);


}

	public function getAddrByIDzg(){
		$id=$_GET[cid];
	$chaxun=$this->db->YOne("select * from `@#_zg_yonghu_yys_record` where id=$id" );
	

		$yyslist['code']=0;
		 $yyslist[data][0][contactID]=$chaxun[uid];
            $yyslist[data][0][contactUserID]=$chaxun[uid];
            $yyslist[data][0][contactName]=$chaxun[shouhuoren];
            $yyslist[data][0][contactAddress]=$chaxun[mobile];
            $yyslist[data][0][contactZip]=$chaxun[youbian];
            $yyslist[data][0][contactMobile]=$chaxun[mobile];
            $yyslist[data][0][contactTel]=$chaxun[tell];
            $yyslist[data][0][contactDefault]=$chaxun[mobile];
            $yyslist[data][0][areaAID]= $chaxun[mobile];
            $yyslist[data][0][areaBID]= $chaxun[mobile];;
            $yyslist[data][0][areaCID]=$chaxun[mobile];
            $yyslist[data][0][areaDID]=$chaxun[mobile];
            $yyslist[data][0][areaAName]=$chaxun[sheng];
            $yyslist[data][0][areaBName]=$chaxun[shi];
            $yyslist[data][0][areaCName]=$chaxun[xian];
            $yyslist[data][0][areaDName]=$chaxun[jiedao];
		echo json_encode($yyslist);
	
	}

	public function confirmAddrzg(){
		$yys[code]=0;
		echo json_encode($yys);
	}
	
	public function editUserContactzg(){
		/*
		$mysql_model=$this->db=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid=$huiyuan['uid'];
		$jiedao=$_POST[Address];
		$shouhuoren=$_POST[Name];
		$OrderAddress=$_POST[OrderAddress];
		$mobile=$_POST[Phone];
		$OrderAddress=$_POST[OrderAddress];
		$retArr = explode(' ',$OrderAddress);
		$sheng=$retArr[0];
		$shi=$retArr[1];
		$xian=$retArr[2];
		$youbian=$_POST[Zip];
		$DID=$_POST[DID];
		$time=time();
		$iii=$_POST[OID];
		$isOldAddr = intval($_POST['isOldAddr']);

		$recordmmm=$mysql_model->YList("select * from `@#_zg_yonghu_yys_record` where `code`='$iii' and `uid`='$huiyuan[uid]' LIMIT 1");
		$shopinfoss=$mysql_model->YOne("select * from `@#_zg_shangpin` where `id`='$recordmmm[shopid]' LIMIT 1");
		if($recordmmm['0']['leixing']==0)
		{
			
			$status='已付款,未发货,未完成,已提交地址';
			
		}else{
			$status='已付款,已发货,已完成';
			
		}
		$gg = "UPDATE `@#_zg_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where code='".$iii."'";
		
		if(!$isOldAddr){
			$ii1 = $this->db->Query("INSERT INTO `@#_yonghu_dizhi`(`uid`,`sheng`,`shi`,`xian`,`jiedao`,`youbian`,`shouhuoren`,`tell`,`mobile`,`qq`,`default`,`time`,`email`)VALUES
			('$uid','$sheng','$shi','$xian','$jiedao','$youbian','$shouhuoren','$tell','$mobile','$qq','$default','$time','$email')");
		}else{
			$ii1 = true;
		}
		$ii2=$this->db->Query("UPDATE `@#_zg_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where code='".$iii."'");
		if($ii1&&$ii2){
			$list[code]=0;
		}
		echo json_encode($list);*/
		$mysql_model=$this->db=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid=$huiyuan['uid'];
		$jiedao=$_POST[Address];
		$shouhuoren=$_POST[Name];
		$OrderAddress=$_POST[OrderAddress];
		$mobile=$_POST[Phone];
		$OrderAddress=$_POST[OrderAddress];
		$retArr = explode(' ',$OrderAddress);
		$sheng=$retArr[0];
		$shi=$retArr[1];
		$xian=$retArr[2];
		$youbian=$_POST[Zip];
		$DID=$_POST[DID];
		$time=time();
		$iii=$_POST[OID];
		$recordmmm=$mysql_model->YOne("select * from `@#_zg_yonghu_yys_record` where `id`='$iii' and `uid`='$huiyuan[uid]' LIMIT 1");
		$shopinfoss=$mysql_model->YOne("select * from `@#_shangpin` where `id`='$recordmmm[shopid]' LIMIT 1");
		
		
		$orderList = $mysql_model->YList("select * from `@#_zg_yonghu_yys_record` where `code` = '$recordmmm[code]'");
		
		if($_POST['isOldAddr']){
			$isOldAddr = $_POST['isOldAddr'];
			if($recordmmm['leixing']==0){
				$status='已付款,未发货,未完成,已提交地址';
			}else{
				$status='已付款,已发货,已完成';
			}
			$gg="UPDATE `@#_zg_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where id='".$iii."'";

			$ii1 = $this->db->Query("UPDATE `@#_yonghu_dizhi` SET `sheng` = '$sheng',`shi` = '$shi',`xian` = '$xian',`jiedao` = '$jiedao',`youbian` = '$youbian',`shouhuoren` = '$shouhuoren',`tell` = '$tell',`mobile` = '$mobile',`qq` = '$qq' WHERE `id` = '$isOldAddr'");
			foreach($orderList as $key => $one){
				$ii2=$this->db->Query("UPDATE `@#_zg_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where id='".$one['id']."'");
			}
			if($ii1&&$ii2){
				$list[code]=5;
			}
		}else{
			if($recordmmm['leixing']==0){
				$status='已付款,未发货,未完成,已提交地址';
			}else{
				$status='已付款,已发货,已完成';
			}
			

			$gg="UPDATE `@#_zg_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where id='".$iii."'";
			
			$ii1=$this->db->Query("INSERT INTO `@#_yonghu_dizhi`(`uid`,`sheng`,`shi`,`xian`,`jiedao`,`youbian`,`shouhuoren`,`tell`,`mobile`,`qq`,`default`,`time`,`email`) VALUES ('$uid','$sheng','$shi','$xian','$jiedao','$youbian','$shouhuoren','$tell','$mobile','$qq','$default','$time','$email')");

			$ii2=$this->db->Query("UPDATE `@#_zg_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where id='".$iii."'");
			if($ii1&&$ii2){
				$list[code]=0;
			}
		}
		echo json_encode($list);
}

//直购结束
	public function getAddrByID(){
		$id=$_GET[cid];
		$chaxun=$this->db->YOne("select * from `@#_yonghu_yys_record` where id=$id" );
	

		$yyslist['code']=0;
		 $yyslist[data][0][contactID]=$chaxun[uid];
            $yyslist[data][0][contactUserID]=$chaxun[uid];
            $yyslist[data][0][contactName]=$chaxun[shouhuoren];
            $yyslist[data][0][contactAddress]=$chaxun[mobile];
            $yyslist[data][0][contactZip]=$chaxun[youbian];
            $yyslist[data][0][contactMobile]=$chaxun[mobile];
            $yyslist[data][0][contactTel]=$chaxun[tell];
            $yyslist[data][0][contactDefault]=$chaxun[mobile];
            $yyslist[data][0][areaAID]= $chaxun[mobile];
            $yyslist[data][0][areaBID]= $chaxun[mobile];;
            $yyslist[data][0][areaCID]=$chaxun[mobile];
            $yyslist[data][0][areaDID]=$chaxun[mobile];
            $yyslist[data][0][areaAName]=$chaxun[sheng];
            $yyslist[data][0][areaBName]=$chaxun[shi];
            $yyslist[data][0][areaCName]=$chaxun[xian];
            $yyslist[data][0][areaDName]=$chaxun[jiedao];
		echo json_encode($yyslist);
	
	}

	public function confirmAddr(){
	$yys[code]=0;
	echo json_encode($yys);
	}
public function editUserContact(){
	
		$mysql_model=$this->db=System::DOWN_sys_class('model');
		$huiyuan=$this->userinfo;
		$uid=$huiyuan['uid'];
		$jiedao=$_POST[Address];
		$shouhuoren=$_POST[Name];
		$OrderAddress=$_POST[OrderAddress];
		$mobile=$_POST[Phone];
		$OrderAddress=$_POST[OrderAddress];
		$retArr = explode(' ',$OrderAddress);
		$sheng=$retArr[0];
		$shi=$retArr[1];
		$xian=$retArr[2];
		$youbian=$_POST[Zip];
		$DID=$_POST[DID];
		$time=time();
		$iii=$_POST[OID];
		$recordmmm=$mysql_model->YOne("select * from `@#_yonghu_yys_record` where `id`='$iii' and `uid`='$huiyuan[uid]' LIMIT 1");
		$shopinfoss=$mysql_model->YOne("select * from `@#_shangpin` where `id`='$recordmmm[shopid]' LIMIT 1");
				


	if($recordmmm['leixing']==0)
	{
		
		$status='已付款,未发货,未完成,已提交地址';
		
	}else{
		$status='已付款,已发货,已完成';
		
	}
		$gg="UPDATE `@#_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where id='".$iii."'";

		$ii1=$this->db->Query("INSERT INTO `@#_yonghu_dizhi`(`uid`,`sheng`,`shi`,`xian`,`jiedao`,`youbian`,`shouhuoren`,`tell`,`mobile`,`qq`,`default`,`time`,`email`)VALUES
			('$uid','$sheng','$shi','$xian','$jiedao','$youbian','$shouhuoren','$tell','$mobile','$qq','$default','$time','$email')");

			$ii2=$this->db->Query("UPDATE `@#_yonghu_yys_record` SET shouhuo='1',status='$status',qq='$qq',youbian='$youbian',shipRemark='$shipRemark',shipTime='$shipTime',email='$email',tell='$tell',shouhuoren='$shouhuoren',mobile='$mobile',sheng='$sheng',shi='$shi',xian='$xian',jiedao='$jiedao',fhtime='$time',wei='0' where id='".$iii."'");
if($ii1&&$ii2){
	$list[code]=0;
}
echo json_encode($list);
		
		
	
}
	public function getChildArea(){
		$areaID=$_GET[areaID];
		$city=$this->db->Ylist("select * from `city` where pid=$areaID");
		$yys[code]=0;
		foreach ($city as $key=>$val){
			$yys[data][$key]['areaID']=$val[id];
			$yys[data][$key]['areaName']=$val[name];
			$yys[data][$key]['areaPID']=$val[pid];
			$yys[data][$key]['areaZip']=$val[Zone];
			$yys[data][$key]['areaRank']=0;
		}

		echo json_encode($yys);
	}
	//晒单json

	public function shaidan(){
		$_GET = array_change_key_case($_GET, CASE_LOWER);
		$fidx=htmlspecialchars($_GET[fidx])-1;
	   $eidx=htmlspecialchars($_GET[eidx]);
	   $id=htmlspecialchars($_GET[goodsid]);
	
		if($id){
			$shaidingdan=$this->db->Ylist("select * from `@#_shai` where `sd_shopid` IN ($id) order by `sd_id` DESC limit $fidx,$eidx");
		$count=$this->db->Ylist("select * from `@#_shai` where `sd_shopid` IN ($id) order by `sd_id` DESC");
		foreach($shaidingdan as $sd){
				$shaidingdan_hueifu=$this->db->Ylist("select * from `@#_shai_hueifu` where `sdhf_id`='$sd[sd_id]'");
				$sum=$sum+count($shaidingdan_hueifu);
			}
		if(empty($sum)){
		$yyslist['code']=1;
		}
		else{
		$yyslist['code']=0;
		$yyslist['CountEx']=$sum;
		$yyslist['Count']=count($count);
		foreach($shaidingdan as $key=>$val){
			
			$yyslist['Data'][$key]['username']=huode_user_name($val['sd_userid']);
			$yyslist['Data'][$key]['userphoto']=$val['sd_thumbs'];
			$yyslist['Data'][$key]['userweb']=$val['sd_userid'];
			$yyslist['Data'][$key]['codeperiod']=$val['sd_qishu'];
			$yyslist['Data'][$key]['postid']=$val['sd_id'];
			$yyslist['Data'][$key]['posttitle']=$val['sd_title'];
			$yyslist['Data'][$key]['postContent']=$val['sd_content'];
			$yyslist['Data'][$key]['postAllPic']=$val['sd_photolist'];
			$yyslist['Data'][$key]['postHits']=$val['shopid'];
			$yyslist['Data'][$key]['postReplyCount']=$val['sd_ping'];
			$yyslist['Data'][$key]['grade']=$val['shopid'];
			$yyslist['Data'][$key]['gradeName']=$val['shopid'];
			$yyslist['Data'][$key]['postTimeEx']=microt($val['sd_time']);


		 } 
		}
		}
		echo json_encode($yyslist);

	}
	//最新揭晓商品
	public function show_newjxshop(){
	
		//最新揭晓
		$yysqishu=$this->db->Ylist("select * from `@#_shangpin` where `q_end_time` !='' ORDER BY `q_end_time` DESC LIMIT 4");
		
		echo json_encode($yysqishu);
	
	}	
	
	//即将揭晓商品
	public function show_msjxshop(){
	      //暂时没做
		  
		  
		  
		//即将揭晓商品
	    $yyslist['listItems'][0]['codeid']=14;  //商品id
	    $yyslist['listItems'][0]['period']=3;  //商品期数
	    $yyslist['listItems'][0]['goodssnme']='苹果';  //商品名称
	    $yyslist['listItems'][0]['seconds']=10;  //商品名称
		
		$yyslist['errorCode']=0;
		//echo json_encode($yyslist);
	
	}
	
    //购物车数量
	public function cartnum(){	  
	  $Mcartlist=$this->Mcartlist;
	  if(is_array($Mcartlist)){
	  	  $gouwuchenum['code']=0;
	      $gouwuchenum['num']=count($Mcartlist);	  
	  }else{
	  	  $gouwuchenum['code']=1;
	      $gouwuchenum['num']=0;	  
	  }
      //var_dump($Mcartlist);
	  echo json_encode($gouwuchenum);
	}
	
	//添加购物车
	public function addShopCart(){
		$_GET = array_change_key_case($_GET, CASE_LOWER);

	  $ShopId=safe_replace($this->segment(4));
	  
	  $shopnum=safe_replace($this->segment(5));
	  if(empty($ShopId)){
	  $ShopId=htmlspecialchars($_GET[codeid]);
	  }

	  if(empty($shopnum)){
	  $shopnum=htmlspecialchars($_GET[shopnum]);
	  }
	  $gouwuchebs=safe_replace($this->segment(6));//标识从哪里加的购物车
	  
	  $shopis=0;          //0表示不存在  1表示存在
	  $Mcartlist=$this->Mcartlist;
	if($ShopId==0 || $shopnum==0){
	  
	  $gouwuche['code']=1;   //表示添加失败
	
	}else{ 
		  if(is_array($Mcartlist)){
			foreach($Mcartlist as $key=>$val){
			   if($key==$ShopId){
			      if(isset($gouwuchebs) && $gouwuchebs=='cart'){
	                $Mcartlist[$ShopId]['num']=$shopnum;
				  }else{
				    $Mcartlist[$ShopId]['num']=$val['num']+$shopnum;
				  }
				  $shopis=1;
			   }else{
				  $Mcartlist[$key]['num']=$val['num'];
			   }
			}    
		  
		  }else{
			  $Mcartlist =array();		  
			  $Mcartlist[$ShopId]['num']=$shopnum; 
		  }  
         

           if($shopis==0){
		     $Mcartlist[$ShopId]['num']=$shopnum;
		   }
		   
       _setcookie('Cartlist',json_encode($Mcartlist),'');   
	  $gouwuche['code']=0;   //表示添加成功	
	}
	 	
	  $gouwuche['num']=count($Mcartlist);    //表示现在购物车有多少条记录
	  
	  echo json_encode($gouwuche);
	  
	}
	
	public function delCartItem(){
	   $ShopId=safe_replace($this->segment(4));
	   
	   $gouwuchelist=$this->Mcartlist;
	   
		if($ShopId==0){
		  
		  $gouwuche['code']=1;   //删除失败
		
		}else{ 
			   if(is_array($gouwuchelist)){
			      if(count($gouwuchelist)==1){
				     foreach($gouwuchelist as $key=>$val){
					   if($key==$ShopId){
					     $gouwuche['code']=0;	
						    _setcookie('Cartlist','','');
						}else{
					     $gouwuche['code']=1;	
					   }
					 }
				     
				  }else{
					   foreach($gouwuchelist as $key=>$val){
							if($key==$ShopId){							  	
							  $gouwuche['code']=0;							  
							}else{
							  $Mcartlist[$key]['num']=$val['num'];
							}
						}
						 					
						   _setcookie('Cartlist',json_encode($Mcartlist),'');   
						 
					}
				    
				}else{
				   $gouwuche['code']=1;   //删除失败
				}
		    
		}		
		echo json_encode($gouwuche);	
	}
	
	public function getCodeState(){

	  $_GET = array_change_key_case($_GET, CASE_LOWER);
	   $xiangmuid=htmlspecialchars($_GET['codeid']);
	   //var_dump($xiangmuid);
	   //exit;
	  
	  $xiangmu=$this->db->YOne("select id,sid,cateid,brandid,title,title,title2,keywords,description,money,yunjiage,zongrenshu,canyurenshu,shenyurenshu,def_renshu,qishu,maxqishu,thumb,picarr,codes_table,xsjx_time,pos,renqi,time,q_uid,q_user,q_user_code,q_content,q_counttime,q_end_time,q_showtime,renqi1,ka,mi,ex_yuedingzhongjiang,cardId,cardPwd,cardId1,leixing,yuanjia,q_end_cp,fahuo from `@#_shangpin` where `id`='".$xiangmuid."' and q_showtime='Y' LIMIT 1");
	  //var_dump($xiangmuid);
	   //exit;
	  
	  if(!$xiangmu){
	     $a['Code']=0;
	  }else{
	  $a['Code']=0;
	  $times123 =  str_ireplace(".","",$xiangmu['q_end_time']);
	  
			$q_time123 = substr($xiangmu['q_end_time'],0,10);	
			$q = false;
			//var_dump(time() >= $q_time123);
			if(time() >= $q_time123){
				
				$q = $this->db->Query("update `@#_shangpin` SET `q_showtime` = 'N' where `id` = '$xiangmuid' and `q_showtime` = 'Y' and `q_uid` is not null");	
			}
			if($q){
			$a['State']=3;
			}
	  }
	   
	 echo json_encode($a);	
	}
	
	
	//login
	public function userlogin(){	
		
		$weername = safe_replace($_POST['username']);
		$password = md5(safe_replace($_POST['password']));
        $verify = md5(strtoupper($_POST['verify']));


        
		$logintype='';
		if(strpos($weername,'@')==false){
			//手机				
			$logintype='mobile';							
		}else{
			//邮箱
			$logintype='email';				
		}
		
		$huiyuan=$this->db->YOne("select * from `@#_yonghu` where `$logintype`='$weername' and `password`='$password'");

		if(!$huiyuan){
			//帐号不存在错误
			$weer['state']=1;
			$weer['num']=-2;
		}
		$check = $logintype."code";
		if($huiyuan[$check] != 1){
			$weer['state']=2; //未验证
		}
		
		if(!is_array($huiyuan)){
			//帐号或密码错误
			$weer['state']=1;
			$weer['num']=-1;
		}else{
		   //登录成功 
		   //限制登陆补丁
					session_start(); 
		$session_id=session_id();
		$ip = _huode_ip_dizhi();
		$time = time();
		$this->db->Query("UPDATE `@#_yonghu` SET session_id='$session_id',`user_ip`='$ip',`login_time`='$time' where uid='$huiyuan[uid]'");
		 //限制登陆补丁
			_setcookie("uid",_encrypt($huiyuan['uid']),60*60*24*7);			
			_setcookie("ushell",_encrypt(md5($huiyuan['uid'].$huiyuan['password'].$huiyuan['mobile'].$huiyuan['email'])),60*60*24*7);	
			
			$weer['state']=0; 
	
		}
		echo json_encode($weer);
	}
	
	//登录成功后
	public function loginok(){	  
	  
	  $weer['Code']=0; 
	  echo json_encode($weer);
	}
	/***********************************注册*********************************/
	
	public function login_by_uid(){
		$huiyuan=$this->db->YOne("select * from `@#_yonghu` where uid = ".$_GET['uid']);
		session_start(); 
		$session_id=session_id();
		$ip = _huode_ip_dizhi();
		$time = time();
		$this->db->Query("UPDATE `@#_yonghu` SET session_id='$session_id',`user_ip`='$ip',`login_time`='$time' where uid='$huiyuan[uid]'");
		_setcookie("uid",_encrypt($huiyuan['uid']),60*60*24*7);			
		_setcookie("ushell",_encrypt(md5($huiyuan['uid'].$huiyuan['password'].$huiyuan['mobile'].$huiyuan['email'])),60*60*24*7);
		$referer =  $_SERVER["HTTP_REFERER"];
		if($referer && strstr($referer,'m.') ){
			header('Location:'.$referer);
		}else{
			header('Location:http://m.tejiadd.com/');
		}
	}

	//检测用户是否已注册
	public function checkname(){
	    $config_email = System::DOWN_sys_config("email");
		$config_mobile = System::DOWN_sys_config("mobile");
		
		$weer = array();
		$name= $this->segment(4);
			
		$regtype=null;
		if(_checkmobile($name)){
				$regtype='mobile';
				$cfg_mobile_type  = 'cfg_mobile_'.$config_mobile['cfg_mobile_on'];
				$config_mobile = $config_mobile[$cfg_mobile_type];
				if(empty($config_mobile['mid']) && empty($config_email['mpass'])){
					 $weer['state']=2;//_notemobile("系统短息配置不正确!");
					echo json_encode($weer);
					exit;
				}				
						
		}		
		$huiyuan=$this->db->YOne("SELECT * FROM `@#_yonghu` WHERE `mobile` = '$name' LIMIT 1");	
					
		if(is_array($huiyuan)){
			if($huiyuan['mobilecode']==1 || $huiyuan['emailcode']==1){			  
			  $weer['state']=1;//_notemobile("该账号已被注册");
			}else{
			  $sql="DELETE from`@#_yonghu` WHERE `mobile` = '$name'";				   
			  $this->db->Query($sql);	
			  $weer['state']=0;			  
			}			
		}else{
		    $weer['state']=0;//表示数据库里没有该帐号
		}	
		 
	    echo json_encode($weer);
	}
	
	//将数据注册到数据库
	public function userMobile(){	
		$name = safe_replace($_POST['username']);
		$pass = md5(safe_replace($_POST['password']));
        $verify = md5(strtoupper($_POST['verify']));
        if($verify!=_getcookie('checkcode')){
            $weerMobile['state']=-1;
            echo json_encode($weerMobile);
            exit;
        }
		$time=time();	
		session_start();
		$decode = $_SESSION['uu'];
        $fid = $_SESSION['fid'];
		$decode2=$_SESSION['yaoqing2'];
		$decode3=$_SESSION['yaoqing3'];

		//exit;
		//邮箱验证 -1 代表未验证， 1 验证成功 都不等代表等待验证
		$sql="INSERT INTO `@#_yonghu`(`mobile`,password,img,emailcode,mobilecode,yaoqing,yaoqing2,yaoqing3,yaoqing4,time,fid)VALUES('$name','$pass','photo/member.jpg','-1','-1','$decode','$decode2','$decode3','$decode4','$time','$fid')";
		if($this->db->Query($sql)){		
			$weerMobile['state']=0;
		}else{
			$weerMobile['state']=1;
		}
		echo json_encode($weerMobile);
	}
	
	//验证输入的手机验证码
	public function mobileregsn(){
	    $mobile= safe_replace($this->segment(4));	
	    $checkcodes= $this->segment(5);	
	    
		$huiyuan=$this->db->YOne("SELECT * FROM `@#_yonghu` WHERE `mobile` = '$mobile' LIMIT 1");
		 
			if(strlen($checkcodes)!=6){
			    //_notemobile("验证码输入不正确!");
				$mobileregsn['state']=1;
				echo json_encode($mobileregsn);
				exit;
			}
			$weercode=explode("|",$huiyuan['mobilecode']);
			if($checkcodes!=$weercode[0]){
			   //_notemobile("验证码输入不正确!");
				$mobileregsn['state']=1;
				echo json_encode($mobileregsn);
				exit;
			}
					
			$fili_yys = System::DOWN_App_config("user_fufen");
			 $this->db->Query("UPDATE `@#_yonghu` SET `score`=`score`+'$fili_yys[f_phonecode]',`jingyan`=`jingyan`+'$fili_yys[z_phonecode]' where `uid`='$huiyuan[uid]'");		
			$this->db->Query("UPDATE `@#_yonghu` SET mobilecode='1' where `uid`='$huiyuan[uid]'");
			
			_setcookie("uid",_encrypt($huiyuan['uid']),60*60*24*7);	
			_setcookie("ushell",_encrypt(md5($huiyuan['uid'].$huiyuan['password'].$huiyuan['mobile'].$huiyuan['email'])),60*60*24*7);
						
			 $mobileregsn['state']=0;
			 $mobileregsn['str']=1;	   
	
	        echo json_encode($mobileregsn);
	} 
	
	//手机绑定开始
	public function mobileregbind(){
	    $mobile= $this->segment(4);
	    $checkcodes= $this->segment(5);
        $huiyuan=$this->userinfo;
		$member=$this->db->YOne("SELECT * FROM `@#_yonghu` WHERE `uid` = $huiyuan[uid] and `mobilecode`!=1 LIMIT 1");
		if(!$member){
			$mobileregsn['state']="该账号己绑定手机!!";
			echo json_encode($mobileregsn);
			exit;
		}
		$isbind=$this->db->YOne("SELECT * FROM `@#_yonghu` WHERE `mobile` = '$mobile' LIMIT 1");
		if($isbind){
			$mobileregsn['state']="该手机已被使用!";
			echo json_encode($mobileregsn);
			exit;
		}
		if(strlen($checkcodes)!=6){
		    //_notemobile("验证码输入不正确!");
			$mobileregsn['state']="验证码输入不正确";
			echo json_encode($mobileregsn);
			exit;
		}
		$usercode=explode("|",$member['mobilecode']);
		if($checkcodes!=$usercode[0]){
		   //_notemobile("验证码输入不正确!");
			$mobileregsn['state']="验证码输入不正确";
			echo json_encode($mobileregsn);
			exit;
		}
        $time=time();

		$find = 0;
		if($member['code']){
			$codeInfo=$this->db->YOne("SELECT * FROM `@#_activity_code` WHERE `code` = '{$member['code']}' and `status`=0 LIMIT 1");
			if($codeInfo){
				$find = 1;
			}
		}

		if($find){
			$procode = $codeInfo['pro'];
			
			if($procode){
				$p_u = $this->db->YOne("select uid,mobile from `@#_yonghu` where `mobile`='{$procode}'");
			}
			if($p_u){
				$this->db->Query("UPDATE `@#_yonghu` SET mobilecode='1',mobile='{$mobile}' where `uid`='$member[uid]'");
				_notemobile("棒定成功");
				exit;
			}else{
				$this->db->Query("UPDATE `@#_yonghu` SET mobilecode='1',mobile='{$mobile}' where `uid`='$member[uid]'");
			}
			$this->db->Query("UPDATE `@#_activity_code` SET `status`=1,`mobile`='$mobile',`date`=now() where `id`='$codeInfo[id]'");

		}else{
			$this->db->Query("UPDATE `@#_yonghu` SET mobilecode='1',mobile='{$mobile}' where `uid`='$member[uid]'");
		}

		$member['mobile'] = $mobile;
		_setcookie("uid",_encrypt($member['uid']));
		_setcookie("ushell",_encrypt(md5($member['uid'].$member['password'].$member['mobile'].$member['email'])));

		$config = System::DOWN_app_config("user_fufen");//福分/经验
		$time=time();
		
		$this->db->Query("insert into `@#_yonghu_zhanghao` (`uid`,`type`,`pay`,`content`,`money`,`time`) values ('$huiyuan[uid]','1','福分','手机认证完善奖励','$config[f_phonecode]','$time')");
		$this->db->Query("UPDATE `@#_yonghu` SET `score`=`score`+'$config[f_phonecode]' where uid='".$huiyuan['uid']."'");

		
		$mobileregsn['state']=0;
		$mobileregsn['str']=1;

        echo json_encode($mobileregsn);
	}


//new重新发送验证码
	public function sendmobcode(){
	  		$name=$this->segment(4);
            $member=$this->userinfo;
	
			//file_put_contents('1.txt', json_encode($member) );
			if(!$member){
			    //_message("参数不正确!");
				$sendmobile['state']=1;
				echo json_encode($sendmobile);
				exit;
		    }
			$checkcode=explode("|",$member['mobilecode']);
			$times=time()-$checkcode[1];
			if($times > 120){

				$sendok = send_mobile_reg_code($name,$member['uid']);
				if($sendok[0]!=1){
					//_message($sendok[1]);exit;
                   	$sendmobile['state']=times;
					echo json_encode($sendmobile);
					exit;
				}
				//成功
				    $sendmobile['state']="ok";
					echo json_encode($sendmobile);
					exit;
			}else{
				    $sendmobile['state']=120-$times;
					echo json_encode($sendmobile);
					exit;
			}

	}

//手机绑定结束

	//重新发送验证码
	public function sendmobile(){
	  
	  		$name=$this->segment(4);
			$huiyuan=$this->db->YOne("SELECT * FROM `@#_yonghu` WHERE `mobile` = '$name' LIMIT 1");
			if(!$huiyuan){
			    //_notemobile("参数不正确!");
				$sendmobile['state']=1;
				echo json_encode($sendmobile);
				exit;    
		    }
			$checkcode=explode("|",$huiyuan['mobilecode']);
			$times=time()-$checkcode[1];		
			if($times > 120){
				
				$sendok = send_mobile_reg_code($name,$huiyuan['uid']);
				if($sendok[0]!=1){
					//_notemobile($sendok[1]);exit;	
                   	$sendmobile['state']=1;	
					echo json_encode($sendmobile);
					exit;                    					
				}  
				//成功
				    $sendmobile['state']=0;	
					echo json_encode($sendmobile);
					exit;  						
			}else{
				    $sendmobile['state']=1;	
					echo json_encode($sendmobile);
					exit; 
			}
	
	}

	public function accountbind(){
		$member=$this->userinfo;
		$username = $_GET['u'];
		$password = md5($_GET['p']);
		$user = $this->db->YOne("select * FROM `@#_yonghu`  where (username = '$username' and password = '$password') OR  (email = '$username' and password = '$password') OR  (mobile = '$username' and password = '$password') ");

		if(!$user){
			$r['state']="帐号或密码错误";
			echo json_encode($r);
			exit();
		}
		if($user['openid']){
			$r['state']="该帐号已绑定微信";
			echo json_encode($r);
			exit();
		}

		if($user && !$user['openid']){
			session_start(); 
			$session_id=session_id();
			$ip = _huode_ip_dizhi();
			$time = time();
			$this->db->Query("UPDATE `@#_yonghu` SET session_id='$session_id',`user_ip`='$ip',`login_time`='$time',`openid`='".$member['openid']."' where uid='$user[uid]'");
			//_setcookie("uid","",time()-3600);
			//_setcookie("ushell","",time()-3600);	
			_setcookie("uid",_encrypt($user['uid']),60*60*24*7);			
			_setcookie("ushell",_encrypt(md5($user['uid'].$user['password'].$user['mobile'].$user['email'])),60*60*24*7);

			$r['state']='0';
			echo json_encode($r);
			exit();
		}
	}

	//最新揭晓
	public function getLotteryList(){
		$_GET = array_change_key_case($_GET, CASE_LOWER);
	   $fidx=htmlspecialchars($_GET[fidx])-1;
	   $eidx=10;//$this->segment(5);
	   $isCount=$this->segment(6);
	   
	   $shopsum=$this->db->Ylist("select id from `@#_shangpin` where `q_end_time` !='' ");
	   
	   //最新揭晓
		$yyslist['listItems']=$this->db->Ylist("select id,sid,cateid,brandid,title,title,title2,keywords,description,money,yunjiage,zongrenshu,canyurenshu,shenyurenshu,def_renshu,qishu,maxqishu,thumb,picarr,codes_table,xsjx_time,pos,renqi,time,q_uid,q_user,q_user_code,q_content,q_counttime,q_end_time,q_showtime,renqi1,ka,mi,ex_yuedingzhongjiang,cardId,cardPwd,cardId1,leixing,yuanjia,q_end_cp,fahuo from `@#_shangpin` where `q_end_time` !=''  and q_showtime!='Y' ORDER BY `q_end_time` DESC limit $fidx,$eidx");
		
		if(empty($yyslist['listItems'])){
		  $yyslist['code']=1;
		}else{
			$gtimes = (int)System::DOWN_sys_config('system','goods_end_time');
		 foreach($yyslist['listItems'] as $key=>$val){
		 //查询出购买次数
		   $recodeinfo=$this->db->YOne("select sum(gonumber) as gonumber from `@#_yonghu_yys_record` where `uid` ='$val[q_uid]'  and `shopid`='$val[id]'");
		   //$ss=$this->db->YOne("select sum(gonumber) as gonumber from `@#_yonghu_yys_record` where `uid` ='$val[q_uid]'  and `shopid`='$val[id]' ");
		   //var_dump($ss[gonumber]);
		   //echo "select `gonumber` from `@#_yonghu_yys_record` where `uid` !='$val[q_uid]'  and `shopid`='$val[id]' ";
		   $yyslist['listItems'][$key]['codeid']=$val['id'];
		   $yyslist['listItems'][$key]['codegoodspic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
		   $yyslist['listItems'][$key]['userphoto']=huode_user_key($val['q_uid'],'img');
		   $yyslist['listItems'][$key]['username']=huode_user_name($val['q_uid']);
		   $yyslist['listItems'][$key]['codeRIpAddr']=$recodeinfo['gonumber'];
		   $yyslist['listItems'][$key]['codeRUserBuyCount']=$recodeinfo['gonumber'];
		   
		   $yyslist['listItems'][$key]['codeRNO']=$recodeinfo['huode'];
		   $yyslist['listItems'][$key]['codeRTime']=microt($val['q_end_time']);
		   $yyslist['listItems'][$key]['userweb']=$val['q_uid'];
		   $yyslist['listItems'][$key]['codetype']=$recodeinfo['gonumber'];
		   $yyslist['listItems'][$key]['goodssnme']=$recodeinfo['shopname'];
		   $yyslist['listItems'][$key]['codeperiod']=$val['qishu'];
		   $yyslist['listItems'][$key]['codeprice']=$val['money'];
		 }
		  $yyslist['code']=0;
		  $yyslist['count']=count($shopsum);
		}		
	 
		echo json_encode($yyslist);
	 
	}
	
	//访问他人购买记录
	public function getUserBuyList(){
	   $type=intval($this->segment(4));
	   $uid=intval($this->segment(5));
	   $fidx=intval($this->segment(6));
	   $eidx=10;//$this->segment(7);
	   $isCount=$this->segment(8);
		$time = time();
		 if($type==0){	 
          //参与汇格同城的商品 全部...
		  $yyslist=$this->db->Ylist("select *,sum(gonumber) as gonumber from `@#_yonghu_yys_record` a left join `@#_shangpin` b on a.shopid=b.id where a.uid='$uid' and b.`q_end_time` < '$time' GROUP BY shopid ");		 
		 
		  $shop['listItems']=$this->db->Ylist("select *,sum(gonumber) as gonumber from `@#_yonghu_yys_record` a left join `@#_shangpin` b on a.shopid=b.id where a.uid='$uid' and b.`q_end_time` < '$time' GROUP BY shopid order by a.time desc limit $fidx,$eidx " );
		 }elseif($type==1){
		   //获得奖品		
		    $yyslist=$this->db->Ylist("select id,sid,cateid,brandid,title,title,title2,keywords,description,money,yunjiage,zongrenshu,canyurenshu,shenyurenshu,def_renshu,qishu,maxqishu,thumb,picarr,codes_table,xsjx_time,pos,renqi,time,q_uid,q_user,q_user_code,q_content,q_counttime,q_end_time,q_showtime,renqi1,ka,mi,ex_yuedingzhongjiang,cardId,cardPwd,cardId1,leixing,yuanjia,q_end_cp,fahuo from  `@#_shangpin`  where q_uid='$uid' and `q_end_time` < '$time'" );
			
		    $shop['listItems']=$this->db->Ylist("select id,sid,cateid,brandid,title,title,title2,keywords,description,money,yunjiage,zongrenshu,canyurenshu,shenyurenshu,def_renshu,qishu,maxqishu,thumb,picarr,codes_table,xsjx_time,pos,renqi,time,q_uid,q_user,q_user_code,q_content,q_counttime,q_end_time,q_showtime,renqi1,ka,mi,ex_yuedingzhongjiang,cardId,cardPwd,cardId1,leixing,yuanjia,q_end_cp,fahuo from  `@#_shangpin`  where q_uid='$uid'  and `q_end_time` < '$time' order by q_end_time desc limit $fidx,$eidx" );
		 }elseif($type==2){
		   //晒单记录
		    $yyslist=$this->db->Ylist("select * from `@#_shai` a left join `@#_shangpin` b on a.sd_shopid=b.id where a.sd_userid='$uid' " );
			
		    $shop['listItems']=$this->db->Ylist("select * from `@#_shai` a left join `@#_shangpin` b on a.sd_shopid=b.id where a.sd_userid='$uid' order by a.sd_time desc limit $fidx,$eidx" );		
			 
		 }
	     
		 if(empty($shop['listItems'])){
		   $shop['code']=4;
		 
		 }else{
		   foreach($shop['listItems'] as $key=>$val){
		      if($val['q_end_time']!=''){
			    $shop['listItems'][$key]['codeState']=3;
			    $shop['listItems'][$key]['q_user']=huode_user_name($val['q_uid']);
                $shop['listItems'][$key]['q_end_time']=microt($val['q_end_time']);
                 				
			  }
			  if(isset($val['sd_time'])){			  
			   $shop['listItems'][$key]['sd_time']=date('m月d日 H:i',$val['sd_time']);
			  }
		   }
		   $shop['code']=0;
		   $shop['count']=count($yyslist);
		 }
		 //ECHO "<PRE>";
	     //PRINT_R($shop);
		 
	   echo json_encode($shop);
	}
	 
	 //查看计算结果
	 public function getGoodsPeriodInfo(){
	 $_GET = array_change_key_case($_GET, CASE_LOWER);
	  $xiangmuid=htmlspecialchars($_GET[goodsid]);
	   $qishu=htmlspecialchars($_GET[period]);
$xiangmu=$this->db->YOne("select id,sid,cateid,brandid,q_content from `@#_shangpin` where `id`='$xiangmuid' and `q_end_time` is not null LIMIT 1");
	   $xiangmuzx=$this->db->YOne("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' and `qishu`='$qishu' order by `qishu` DESC LIMIT 1");
$yys[code]=0;
$yys[codeID]=$xiangmuzx[id];
	   echo json_encode($yys);
	 }
	 
/*补揭晓明细*/
	 public function getCalResult(){
		$_GET = array_change_key_case($_GET, CASE_LOWER);
		$fidx=htmlspecialchars($_GET[fidx])-1;
		$eidx=htmlspecialchars($_GET[eidx]);
		$xiangmuid=htmlspecialchars($_GET[codeid]);
	   
		 $curtime=time();
		 
		 $xiangmu=$this->db->YOne("select id,sid,cateid,brandid,q_content from `@#_shangpin` where `id`='$xiangmuid' and `q_end_time` is not null LIMIT 1");
		$xiangmuzx=$this->db->YOne("select * from `@#_shangpin` where `sid`='$xiangmu[sid]' and `qishu`>'$xiangmu[qishu]' and `q_end_time` is null order by `qishu` DESC LIMIT 1");
	
		if($xiangmu['q_content']){
		    $xiangmu['contcode']=0;
			$xiangmu['itemlist'] = unserialize($xiangmu['q_content']);
		
			foreach($xiangmu['itemlist'] as $key=>$val){
			 // 	$xiangmu['itemlist'][$key]['time']	=microt($val['time']);		 				 
				$h=date("H",$val['time']);
			    $i=date("i",$val['time']);
			    $s=date("s",$val['time']);	
			    list($timesss,$msss) = explode(".",$val['time']);				 
			}
			
		}else{
		    $xiangmu['contcode']=1;
		}

		if(!empty($xiangmu)){
		  $xiangmu['code']=0;
		  
		}else{
		  $xiangmu['code']=1;
		}

		$jilu=$this->db->Ylist("select id,sid,cateid,brandid,time,q_content from `@#_shangpin` where `id`='$xiangmuid' and `q_end_time` is not null");

		//var_dump($xiangmu['itemlist']);
				$yyslist['code']=0;
		
		foreach($xiangmu['itemlist'] as $key=>$val){
							//var_dump($val);
				$yyslist['record0'][$key]['buytime']=microt($val['time']);
				$yyslist['record0'][$key]['buyName']=$val[username];
				$yyslist['record0'][$key]['userweb']=$val[uid];
				$yyslist['record1'][$key]['buytime']=microt($val['time']);
				$yyslist['record1'][$key]['buyName']=$val[username];
				$yyslist['record1'][$key]['userweb']=$val[uid];
				$h=date("H",$val['time']);
			    $i=date("i",$val['time']);
			    $s=date("s",$val['time']);	
			    list($timesss,$msss) = explode(".",$val['time']);
				$yyslist['record1'][$key]['timeCodeVal']=$h.$i.$s.$msss;
				$yyslist['record2'][$key]['userweb']=$val[uid];

				$yyslist['record2'][$key]['buyName']=$val[username];
				$yyslist['record2'][$key]['buytime']=microt($val['time']);



		 }  
		 
    //echo "<pre>";
	//print_r($xiangmu);
	//print_r($record_time);
	   echo json_encode($yyslist);
		
	 
	 }



	 //1级邀请记录
	public function getinvitelist(){
		$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;

		$mingxi=$this->db->YList("select * from `@#_yonghu` where `yaoqing`='$huiyuan[uid]' ORDER BY `time` ASC limit $kaishi,$jieshu");

		if(!$mingxi){
			$yys['code']=-1;
			$yys['tips']="暂无记录";
		}else{
		$yys['code']=0;
		$yys['str']['totalCount']=count($mingxi);

		
foreach ($mingxi as $key=>$val){
	$jilu =$this->db->YOne("select * from `@#_yonghu_yys_record` where `uid`=$val[uid] order by time desc");
$yys['str']['listItems'][$key]['userName']=huode_user_name($val['uid']);
$yys['str']['listItems'][$key]['regTime']=date('Y.m.d H:i:s',$val['time']);
if($jilu){
$yys['str']['listItems'][$key]['state']=1;
}
$yys['str']['listItems'][$key]['userWeb']=$val['uid'];
$yys['str']['listItems'][$key]['userPhoto']=5;
$yys['str']['listItems'][$key]['userCode']=$val['uid']+1000000000;
}
	}
	echo json_encode($yys);
	}

	//2级邀请记录
	public function getinvitelist2(){
		$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;

		$mingxi=$this->db->YList("select * from `@#_yonghu` where `yaoqing2`='$huiyuan[uid]' ORDER BY `time` ASC limit $kaishi,$jieshu");

		if(!$mingxi){
			$yys['code']=-1;
			$yys['tips']="暂无记录";
		}else{
		$yys['code']=0;
		$yys['str']['totalCount']=count($mingxi);

		
foreach ($mingxi as $key=>$val){
	$jilu =$this->db->YOne("select * from `@#_yonghu_yys_record` where `uid`=$val[uid] order by time desc");
$yys['str']['listItems'][$key]['userName']=huode_user_name($val['uid']);
$yys['str']['listItems'][$key]['regTime']=date('Y.m.d H:i:s',$val['time']);
if($jilu){
$yys['str']['listItems'][$key]['state']=1;
}
$yys['str']['listItems'][$key]['userWeb']=$val['uid'];
$yys['str']['listItems'][$key]['userPhoto']=5;
$yys['str']['listItems'][$key]['userCode']=$val['uid']+1000000000;
}
	}
	echo json_encode($yys);
	}


	//1级邀请记录
	public function getinvitelist3(){
		$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;

		$mingxi=$this->db->YList("select * from `@#_yonghu` where `yaoqing3`='$huiyuan[uid]' ORDER BY `time` ASC limit $kaishi,$jieshu");

		if(!$mingxi){
			$yys['code']=-1;
			$yys['tips']="暂无记录";
		}else{
		$yys['code']=0;
		$yys['str']['totalCount']=count($mingxi);

		
foreach ($mingxi as $key=>$val){
	$jilu =$this->db->YOne("select * from `@#_yonghu_yys_record` where `uid`=$val[uid] order by time desc");
$yys['str']['listItems'][$key]['userName']=huode_user_name($val['uid']);
$yys['str']['listItems'][$key]['regTime']=date('Y.m.d H:i:s',$val['time']);
if($jilu){
$yys['str']['listItems'][$key]['state']=1;
}
$yys['str']['listItems'][$key]['userWeb']=$val['uid'];
$yys['str']['listItems'][$key]['userPhoto']=5;
$yys['str']['listItems'][$key]['userCode']=$val['uid']+1000000000;
}
	}
	echo json_encode($yys);
	}
public function getBrokerageInfo(){

		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		$id=htmlspecialchars($_GET[applyID]);

 $recordarr=$this->db->Yone("select * from  `@#_yonghu_cashout`  where `id`='$id' and uid='$uid' ORDER BY `time` DESC limit 1");
 //var_dump($recordarr[username]);
	//var_dump($yaoqing);
	if(empty($recordarr)){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
	$yys['code']="0";
	$yys['data']['applyTime']=date('Y.m.d',$recordarr['time']);
	$yys['data']['fetchMoney']=$recordarr['money'];
	$yys['data']['bankName']=$recordarr['bankname'];
	$yys['data']['subBank']=$recordarr['bankname'];
	$yys['data']['bankAccount']=$recordarr['banknumber'];
	$yys['data']['userName']=$recordarr['username'];
	$yys['data']['serviceMoney']=$recordarr['procefees'];
	if($recordarr['auditstatus']){
	$yys['data']['applyState']="4";
	}else{
	$yys['data']['applyState']="2";
	}
		
	}
	
	
	echo json_encode($yys);
	}

	//提现记录
	public function record(){
$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];


	$count = $this->db->YList("select * from  `@#_yonghu_cashout`  where `uid`='$uid' ORDER BY `time`");
	//var_dump($count);
 $recordarr=$this->db->YList("select * from  `@#_yonghu_cashout`  where `uid`='$uid' ORDER BY `time` DESC limit $kaishi,$jieshu");



	//var_dump($yaoqing);
	if(empty($recordarr)){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
	$yys['code']=0;
	$yys['str']['totalCount']=count($recordarr);
	foreach ($recordarr as $key=>$val){
	
$yys['str']['listItems'][$key]['userName']=$val['username'];
$yys['str']['listItems'][$key]['buyTime']= date('Y.m.d H:i:s',$val['time']);
$yys['str']['listItems'][$key]['codeID']= $val['shopid'];
$yys['str']['listItems'][$key]['period']= "(第".$val['shopqishu']."期)";
$yys['str']['listItems'][$key]['descript']= $val['shopname'];
$yys['str']['listItems'][$key]['buyMoney']=$val['moneycount'];
$yys['str']['listItems'][$key]['brokerage']=$val['money'];
$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
$yys['str']['listItems'][$key]['logType']= "1";
if($val['auditstatus']){
$yys['str']['listItems'][$key]['logType2']= "4";
}else{
$yys['str']['listItems'][$key]['logType2']= "2";
}
if($val['auditstatus']){
$yys['str']['listItems'][$key]['applyState']= "4";
}
$yys['str']['listItems'][$key]['applyID']= $val['id'];;

		
	}
	}

	echo json_encode($yys);
	}

//佣金冲值记录

public function record1(){
$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];


	 $count1 = $this->db->YList("select * from `@#_yonghu_zhanghao` where `uid`='$uid'  ORDER BY `time`");
	
 $chongzhi=$this->db->YList("select * from `@#_yonghu_zhanghao` where `uid`='$uid' and type=1 and pay='佣金' ORDER BY `time` DESC limit $kaishi,$jieshu");



	//var_dump($yaoqing);
	if(empty($chongzhi)){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
	$yys['code']=0;
	$yys['str']['totalCount']=count( $chongzhi);
	foreach ($chongzhi as $key=>$val){
	
$yys['str']['listItems'][$key]['userName']=$val['username'];
$yys['str']['listItems'][$key]['buyTime']= date('Y.m.d H:i:s',$val['time']);
$yys['str']['listItems'][$key]['codeID']= $val['shopid'];
$yys['str']['listItems'][$key]['period']= "(第".$val['shopqishu']."期)";
$yys['str']['listItems'][$key]['descript']= $val['shopname'];
$yys['str']['listItems'][$key]['buyMoney']=$val['moneycount'];

$yys['str']['listItems'][$key]['brokerage']=$val['money'];
$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
$yys['str']['listItems'][$key]['logType']= "1";

$yys['str']['listItems'][$key]['logType2']= "2";

$yys['str']['listItems'][$key]['applyState']= "";

$yys['str']['listItems'][$key]['applyID']= $val['id'];;

		
	}
	}

	echo json_encode($yys);
	}


	//1级佣金明细111
	public function getcommissionlist(){
$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		
		$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_recodes` on `@#_yonghu`.uid = `@#_yonghu_recodes`.cashoutid  where `@#_yonghu`.yaoqing='$huiyuan[uid]'  and `@#_yonghu_recodes`.uid=$huiyuan[uid] and type=1 order by `@#_yonghu_recodes`.time desc limit $kaishi,$jieshu");

		$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_recodes` on `@#_yonghu`.uid = `@#_yonghu_recodes`.cashoutid  where `@#_yonghu`.yaoqing='$huiyuan[uid]'  and `@#_yonghu_recodes`.uid=$huiyuan[uid] and type=1");

	if(empty($yaoqing[0][uid])){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
		$yys['code']=0;
		$yys['str']['totalCount']=count($count);
		foreach ($yaoqing as $key=>$val){
			/*if($val['cashoutid'] ){
				$chacha=$this->db->YOne("select * from `@#_yonghu` where `uid`=".$val['cashoutid'] );
				$yys['str']['listItems'][$key]['userName'] = $chacha['username'];

			}else{
				$yys['str']['listItems'][$key]['userName']=$val['username'];
			}*/
			$yys['str']['listItems'][$key]['userName']=$val['username'];

			$yys['str']['listItems'][$key]['buyTime']= date('Y-m-d H:i:s',$val['time']);

			$yys['str']['listItems'][$key]['content']= $val['content'];
			$yys['str']['listItems'][$key]['descript']= $val['content'];
			$yys['str']['listItems'][$key]['buyMoney']=$val['ygmoney'];
			$yys['str']['listItems'][$key]['brokerage']=$val['money'];

			$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
			$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
			$yys['str']['listItems'][$key]['logType']= "1";
			$yys['str']['listItems'][$key]['logType2']= "1";
			$yys['str']['listItems'][$key]['applyState']= "";
			$yys['str']['listItems'][$key]['applyID']= "";
			
		}
	}
	
	/*$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.yaoqing='$huiyuan[uid]' order by id desc limit $kaishi,$jieshu");

	$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.yaoqing='$huiyuan[uid]'");

	
	if(empty($yaoqing[0][uid])){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
	$yys['code']=0;
	$yys['str']['totalCount']=count($count);
	foreach ($yaoqing as $key=>$val){

$yys['str']['listItems'][$key]['userName']=$val['username'];
$yys['str']['listItems'][$key]['buyTime']= microt($val['time']);
$yys['str']['listItems'][$key]['codeID']= $val['shopid'];
$yys['str']['listItems'][$key]['period']= "(第".$val['shopqishu']."期)";
$yys['str']['listItems'][$key]['descript']= $val['shopname'];
$yys['str']['listItems'][$key]['buyMoney']=$val['moneycount'];

if(empty($val['uid'])){
	$yys['str']['listItems'][$key]['brokerage']="0"; //$val['ymoney3'];
}else{
	//echo "select * from `@#_yonghu_recodes` where `uid`=".$val['uid']."<br>";
	$chacha=$this->db->YOne("select * from `@#_yonghu_recodes` where `uid`=".$val['uid']);
	$yys['str']['listItems'][$key]['brokerage']=$chacha['money']; //$val['ymoney3'];
	
}
//$yys['str']['listItems'][$key]['brokerage']=$val['yongjin']; //$val['ymoney'];
$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
$yys['str']['listItems'][$key]['logType']= "1";
$yys['str']['listItems'][$key]['logType2']= "1";
$yys['str']['listItems'][$key]['applyState']= "";
$yys['str']['listItems'][$key]['applyID']= "";
		
	}
	}*/
	
	echo json_encode($yys);
	}
	


	//2级佣金明细111
	public function getcommissionlist2(){
$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		
		$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_recodes` on `@#_yonghu`.uid = `@#_yonghu_recodes`.cashoutid  where `@#_yonghu_recodes`.cashoutid in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]')) and `@#_yonghu_recodes`.uid=$huiyuan[uid] AND type=1 order by `@#_yonghu_recodes`.time desc limit $kaishi,$jieshu"); // 
	
		$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_recodes` on `@#_yonghu`.uid = `@#_yonghu_recodes`.cashoutid  where `@#_yonghu_recodes`.cashoutid in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]')) and `@#_yonghu_recodes`.uid=$huiyuan[uid] AND type=1");

	if(empty($yaoqing[0][uid])){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
		$yys['code']=0;
		$yys['str']['totalCount']=count($count);
		foreach ($yaoqing as $key=>$val){
			$yys['str']['listItems'][$key]['userName']=$val['username'];

			$yys['str']['listItems'][$key]['buyTime']= date('Y-m-d H:i:s',$val['time']);

			$yys['str']['listItems'][$key]['content']= $val['content'];
			$yys['str']['listItems'][$key]['descript']= $val['content'];
			$yys['str']['listItems'][$key]['buyMoney']=$val['ygmoney'];
			$yys['str']['listItems'][$key]['brokerage']=$val['money'];

			$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
			$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
			$yys['str']['listItems'][$key]['logType']= "1";
			$yys['str']['listItems'][$key]['logType2']= "1";
			$yys['str']['listItems'][$key]['applyState']= "";
			$yys['str']['listItems'][$key]['applyID']= "";
			
		}
	}
/*
	$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.yaoqing in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]') order by id desc limit $kaishi,$jieshu"); // 
	
	$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.`yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]')");
	

	//var_dump($yaoqing);
	if(empty($yaoqing[0][uid])){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
	$yys['code']=0;
	$yys['str']['totalCount']=count($count);
	foreach ($yaoqing as $key=>$val){
	
$yys['str']['listItems'][$key]['userName']=$val['username'];
$yys['str']['listItems'][$key]['buyTime']= microt($val['time']);
$yys['str']['listItems'][$key]['codeID']= $val['shopid'];
$yys['str']['listItems'][$key]['period']= "(第".$val['shopqishu']."期)";
$yys['str']['listItems'][$key]['descript']= $val['shopname'];

$yys['str']['listItems'][$key]['buyMoney']=$val['moneycount'];
if(empty($val['uid'])){
	$yys['str']['listItems'][$key]['brokerage']="0"; //$val['ymoney3'];
}else{
	//echo "select * from `@#_yonghu_recodes` where `uid`=".$val['uid']."<br>";
	$chacha=$this->db->YOne("select * from `@#_yonghu_recodes` where `uid`=".$val['uid']);
	$yys['str']['listItems'][$key]['brokerage']=$chacha['money']; //$val['ymoney3'];
	
}
//$yys['str']['listItems'][$key]['brokerage']=$val['ymoney2'];
$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
$yys['str']['listItems'][$key]['logType']= "1";
$yys['str']['listItems'][$key]['logType2']= "1";
$yys['str']['listItems'][$key]['applyState']= "";
$yys['str']['listItems'][$key]['applyID']= "";
		
	}
	}*/
	
	echo json_encode($yys);
	}



	//3级佣金明细111
	public function getcommissionlist3(){
$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		
		$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_recodes` on `@#_yonghu`.uid = `@#_yonghu_recodes`.cashoutid  where `@#_yonghu_recodes`.cashoutid in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]'))) and `@#_yonghu_recodes`.uid=$huiyuan[uid] AND type=1 order by `@#_yonghu_recodes`.time desc limit $kaishi,$jieshu"); // 
	
		$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_recodes` on `@#_yonghu`.uid = `@#_yonghu_recodes`.cashoutid  where `@#_yonghu_recodes`.cashoutid in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]'))) and `@#_yonghu_recodes`.uid=$huiyuan[uid] AND type=1");

	if(empty($yaoqing[0][uid])){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
		$yys['code']=0;
		$yys['str']['totalCount']=count($count);
		foreach ($yaoqing as $key=>$val){
			$yys['str']['listItems'][$key]['userName']=$val['username'];

			$yys['str']['listItems'][$key]['buyTime']= date('Y-m-d H:i:s',$val['time']);

			$yys['str']['listItems'][$key]['content']= $val['content'];
			$yys['str']['listItems'][$key]['descript']= $val['content'];
			$yys['str']['listItems'][$key]['buyMoney']=$val['ygmoney'];
			$yys['str']['listItems'][$key]['brokerage']=$val['money'];

			$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
			$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
			$yys['str']['listItems'][$key]['logType']= "1";
			$yys['str']['listItems'][$key]['logType2']= "1";
			$yys['str']['listItems'][$key]['applyState']= "";
			$yys['str']['listItems'][$key]['applyID']= "";
			
		}
	}

/*
	$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.yaoqing in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]')) order by id desc limit $kaishi,$jieshu"); // 
	
	$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.`yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]'))");
	
	//var_dump($yaoqing);
	if(empty($yaoqing[0][uid])){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
	$yys['code']=0;
	$yys['str']['totalCount']=count($count);
	foreach ($yaoqing as $key=>$val){
	
$yys['str']['listItems'][$key]['userName']=$val['username'];
$yys['str']['listItems'][$key]['buyTime']= microt($val['time']);
$yys['str']['listItems'][$key]['codeID']= $val['shopid'];
$yys['str']['listItems'][$key]['period']= "(第".$val['shopqishu']."期)";
$yys['str']['listItems'][$key]['descript']= $val['shopname'];
$yys['str']['listItems'][$key]['buyMoney']=$val['moneycount'];
if(empty($val['uid'])){
	$yys['str']['listItems'][$key]['brokerage']="0"; //$val['ymoney3'];
}else{
	//echo "select * from `@#_yonghu_recodes` where `uid`=".$val['uid']."<br>";
	$chacha=$this->db->YOne("select * from `@#_yonghu_recodes` where `uid`=".$val['uid']);
	$yys['str']['listItems'][$key]['brokerage']=$chacha['money']; //$val['ymoney3'];
	
}
$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
$yys['str']['listItems'][$key]['logType']= "1";
$yys['str']['listItems'][$key]['logType2']= "1";
$yys['str']['listItems'][$key]['applyState']= "";
$yys['str']['listItems'][$key]['applyID']= "";
		
	}
	}
	*/
	echo json_encode($yys);
	}
	
	//4级佣金明细111
	public function getcommissionlist4(){
$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		
	
	//$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `yaoqing3`='$huiyuan[uid]' order by id desc limit $kaishi,$jieshu");

	//$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `yaoqing3`='$huiyuan[uid]'");
	$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.yaoqing in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]'))) order by id desc limit $kaishi,$jieshu"); // 
	
	$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.`yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]')))");
	
	//var_dump($yaoqing);
	if(empty($yaoqing[0][uid])){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
	$yys['code']=0;
	$yys['str']['totalCount']=count($count);
	foreach ($yaoqing as $key=>$val){
	
$yys['str']['listItems'][$key]['userName']=$val['username'];
$yys['str']['listItems'][$key]['buyTime']= microt($val['time']);
$yys['str']['listItems'][$key]['codeID']= $val['shopid'];
$yys['str']['listItems'][$key]['period']= "(第".$val['shopqishu']."期)";
$yys['str']['listItems'][$key]['descript']= $val['shopname'];
$yys['str']['listItems'][$key]['buyMoney']=$val['moneycount'];

if(empty($val['uid'])){
	$yys['str']['listItems'][$key]['brokerage']="0"; //$val['ymoney3'];
}else{
	//echo "select * from `@#_yonghu_recodes` where `uid`=".$val['uid']."<br>";
	$chacha=$this->db->YOne("select * from `@#_yonghu_recodes` where `uid`=".$val['uid']);
	$yys['str']['listItems'][$key]['brokerage']=$chacha['money']; //$val['ymoney3'];
	
}

$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
$yys['str']['listItems'][$key]['logType']= "1";
$yys['str']['listItems'][$key]['logType2']= "1";
$yys['str']['listItems'][$key]['applyState']= "";
$yys['str']['listItems'][$key]['applyID']= "";
		
	}
	}
	
	echo json_encode($yys);
	}
	//5级佣金明细111
	public function getcommissionlist5(){
$kaishi=htmlspecialchars($_GET[FIdx])-1;
	$jieshu=htmlspecialchars($_GET[EIdx]);
		$huiyuan=$this->userinfo;
		$uid = $huiyuan['uid'];
		
	
	//$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `yaoqing3`='$huiyuan[uid]' order by id desc limit $kaishi,$jieshu");

	//$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `yaoqing3`='$huiyuan[uid]'");
	$yaoqing = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.yaoqing in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]')))) order by id desc limit $kaishi,$jieshu"); // 
	
	$count = $this->db->YList("select * from `@#_yonghu` left join `@#_yonghu_yys_record` on `@#_yonghu`.uid = `@#_yonghu_yys_record`.uid  where `@#_yonghu`.`yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing` in (select uid from `@#_yonghu` where `yaoqing`='$huiyuan[uid]'))))");
	
	//var_dump($yaoqing);
	if(empty($yaoqing[0][uid])){
		$yys['code']=-1;
		$yys['tips']="暂无记录";
	}else{
	$yys['code']=0;
	$yys['str']['totalCount']=count($count);
	foreach ($yaoqing as $key=>$val){
	
$yys['str']['listItems'][$key]['userName']=$val['username'];
$yys['str']['listItems'][$key]['buyTime']= microt($val['time']);
$yys['str']['listItems'][$key]['codeID']= $val['shopid'];
$yys['str']['listItems'][$key]['period']= "(第".$val['shopqishu']."期)";
$yys['str']['listItems'][$key]['descript']= $val['shopname'];
$yys['str']['listItems'][$key]['buyMoney']=$val['moneycount'];
if(empty($val['uid'])){
	$yys['str']['listItems'][$key]['brokerage']="0"; //$val['ymoney3'];
}else{
	//echo "select * from `@#_yonghu_recodes` where `uid`=".$val['uid']."<br>";
	$chacha=$this->db->YOne("select * from `@#_yonghu_recodes` where `uid`=".$val['uid']);
	$yys['str']['listItems'][$key]['brokerage']=$chacha['money']; //$val['ymoney3'];
	
}
$yys['str']['listItems'][$key]['userWeb']= $val['uid'];
$yys['str']['listItems'][$key]['userPhoto']= huode_user_key($val['uid'],'img');
$yys['str']['listItems'][$key]['logType']= "1";
$yys['str']['listItems'][$key]['logType2']= "1";
$yys['str']['listItems'][$key]['applyState']= "";
$yys['str']['listItems'][$key]['applyID']= "";
		
	}
	}
	
	echo json_encode($yys);
	}
	 //付款
	public function UserPay(){
	    
	
	}
	
	//显示两分钟内 马上揭晓的商品
	public function GetStartRaffleAllList(){
	$_GET = array_change_key_case($_GET, CASE_LOWER);
	   $fidx=htmlspecialchars($_GET[fidx]);
	   $eidx=10;//$this->segment(5);
	   $isCount=$this->segment(6);
	   
	  // $shopsum=$this->db->Ylist("select id,sid,cateid,brandid,title,title,title2,keywords,description,money,yunjiage,zongrenshu,canyurenshu,shenyurenshu,def_renshu,qishu,maxqishu,thumb,picarr,codes_table,xsjx_time,pos,renqi,time,q_uid,q_user,q_user_code,q_content,q_counttime,q_end_time,q_showtime,renqi1,ka,mi,ex_yuedingzhongjiang,cardId,cardPwd,cardId1,leixing,yuanjia,q_end_cp,fahuo from `@#_shangpin` where `q_end_time` !='' ");
	   
	   //最新揭晓
		$tongtong=$this->db->Ylist("select id,sid,cateid,brandid,title,title,title2,keywords,description,money,yunjiage,zongrenshu,canyurenshu,shenyurenshu,def_renshu,qishu,maxqishu,thumb,picarr,codes_table,xsjx_time,pos,renqi,time,q_uid,q_user,q_user_code,q_content,q_counttime,q_end_time,q_showtime,renqi1,ka,mi,ex_yuedingzhongjiang,cardId,cardPwd,cardId1,leixing,yuanjia,q_end_cp,fahuo from `@#_shangpin` where `q_end_time` is not null and `q_showtime` = 'Y' ORDER BY `q_end_time`");
		
		if(empty($tongtong)){
		  $yyslist['code']=1;
		}else{
			$yyslist['code']=0;
			$yyslist['errorCode']=0;
			$yyslist['maxSeconds']=time();
			$gtimes = (int)System::DOWN_sys_config('system','goods_end_time');
		$tt=microtime(true);
		 foreach($tongtong as $key=>$val){
		 //查询出购买次数
		   $recodeinfo=$this->db->YOne("select `gonumber` from `@#_yonghu_yys_record` where `uid` ='$val[q_uid]'  and `shopid`='$val[id]' ");
		   
		   //echo "select `gonumber` from `@#_yonghu_yys_record` where `uid` !='$val[q_uid]'  and `shopid`='$val[id]' ";
		   $yyslist['listItems'][$key]['codeid']=$val['id'];
		   $yyslist['listItems'][$key]['goodspic']=YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
		   
		   $yyslist['listItems'][$key]['codeRTime']=microt($val['q_end_time']-$gtimes);
		  // var_dump($val['q_end_time']);
		  
		   
		   $yyslist['listItems'][$key]['codequantity']=$val['zongrenshu'];
			$yyslist['listItems'][$key]['codesales']=$val['canyurenshu'];
			$yyslist['listItems'][$key]['seconds']=$val['q_end_time']-$tt;
		   $yyslist['listItems'][$key]['codetype']=$recodeinfo['gonumber'];
		   $yyslist['listItems'][$key]['goodssnme']=$val['title'];
		   $yyslist['listItems'][$key]['period']=$val['qishu'];
		   $yyslist['listItems'][$key]['price']=$val['money'];
		 }
		 
		}		
	 
		echo json_encode($yyslist);
	}
		
	//忘记密码
public function GetBarcodernoInfo(){
$_GET = array_change_key_case($_GET, CASE_LOWER);
 $id=htmlspecialchars($_GET[codeid]);
	  
	  // var_dump($id);
	   
		$tongtong=$this->db->Yone("select id,sid,cateid,brandid,title,title,title2,keywords,description,money,yunjiage,zongrenshu,canyurenshu,shenyurenshu,def_renshu,qishu,maxqishu,thumb,picarr,codes_table,xsjx_time,pos,renqi,time,q_uid,q_user,q_user_code,q_content,q_counttime,q_end_time,q_showtime,renqi1,ka,mi,ex_yuedingzhongjiang,cardId,cardPwd,cardId1,leixing,yuanjia,q_end_cp,fahuo from `@#_shangpin` where id=$id and `q_showtime` = 'Y'");
		
		if(empty($tongtong)){
		  $yyslist['code']=1;
		}else{
			$yyslist['code']=0;
			$yyslist['errorCode']=0;
			$yyslist['maxSeconds']=time();
			$gtimes = (int)System::DOWN_sys_config('system','goods_end_time');
		$tt=microtime(true);
		 //查询出购买次数
		   $recodeinfo=$this->db->YOne("select * from `@#_yonghu_yys_record` where `uid` ='$tongtong[q_uid]'  and `shopid`='$tongtong[id]' ");
		   
		  //var_dump($recodeinfo['username']);
			$yyslist['codePeriod']=$tongtong['id'];	  
			 $yyslist['codeRNO']=$tongtong['q_user_code'];

			 $yyslist['seconds']=$tongtong['q_end_time']-$tt;
			$yyslist['username']=$recodeinfo['username'];

			$yyslist['codeRTime']=microt($tongtong['q_end_time']-$gtimes);
			$yyslist['buyCount']=$recodeinfo['gonumber'];
			$yyslist['buyip']=$recodeinfo['ip'];
			$yyslist['buyipaddr']=5;

			$yyslist['buydevice']=6;

			$yyslist['buytime']=microt($recodeinfo['time']);
			 $yyslist['price']=$tongtong['money'];
			$yyslist['goodsName']=$tongtong['title'];
			$yyslist['goodspic']=YYS_LOCAL_PATH."/statics/uploads/".$tongtong['thumb'];
			$yyslist['userphoto']=$recodeinfo['uphoto'];
			$yyslist['userweb']=$recodeinfo['uid'];
			$yyslist['codeType']=$recodeinfo['gonumber'];
			$times123 =  str_ireplace(".","",$tongtong['q_end_time']);
			$q_time123 = substr($tongtong['q_end_time'],0,10);	
			$q = false;
			
			if(time() >= $q_time123){
				$q = $this->db->Query("update `@#_shangpin` SET `q_showtime` = 'N' where `id` = '$id' and `q_showtime` = 'Y' and `q_uid` is not null");	
			}
		 
		}		
	
		echo json_encode($yyslist);
	 
}

	public function find(){
		$phone= trim($_POST['phone']);
		if(!_checkmobile($phone)){
			echo json_encode(array('sta'=>'0','msg'=>'请输入有效的手机号码！'));
			die;
		}
		$huiyuan=$this->db->YOne("SELECT * FROM `@#_yonghu` WHERE `mobile` = '$phone' LIMIT 1");
		
		if($huiyuan){
			$randcode=rand(100000,999999);
			$checkcodes=$randcode.'|'.time();
			$this->db->Query("UPDATE `@#_yonghu` SET passcode='$checkcodes' where `uid`='$huiyuan[uid]'");
			$txt = "您的用户名：{$huiyuan['mobile']}，申请重置密码：{$randcode}。如非本人操作请忽略！";
			$sendok=_sendmobile($phone,$txt);
			if($sendok[0]!=1){
				echo json_encode(array('sta'=>'0','msg'=>'验证码发送失败！'));
				die;
			}
			echo json_encode(array('sta'=>'1','msg'=>$phone));
			die;
		}else{
		    echo json_encode(array('sta'=>'0','msg'=>'用户名不存在！'));
			die;
		}
	}

	public function findmobilecheck(){
		$phone = $this->segment(4);
		if(!empty($_POST)){
			$code = trim($_POST['code']);
			$pass1 = trim($_POST['pass1']);
			$pass2 = trim($_POST['pass2']);
			$sql="select * from `@#_yonghu` where `mobile`='$phone' AND `passcode` like '$code%' LIMIT 1";
			$huiyuan=$this->db->YOne($sql);
			if(!$huiyuan){
				echo "验证码错误!";die;
			}
			if($pass1 != $pass2){
				echo "密码不一致!";die;
			}
			$password=md5($pass1);
			$this->db->Query("UPDATE `@#_yonghu` SET `password`='$password',`passcode`='-1' where `uid`='$huiyuan[uid]'");
			echo 1;die;
		}
		if(!_checkmobile($phone)){
			_message("请输入有效的手机号码！!",LOCAL_PATH."/mobile/user/findpassword",3);
		}
		$huiyuan=$this->db->YOne("SELECT * FROM `@#_yonghu` WHERE `mobile` = '$phone' LIMIT 1");
		if($huiyuan['passcode']==-1){
			_message("错误!",LOCAL_PATH."/mobile/user/findpassword",3);
		}
		$biaoti = "身份验证";
		include templates("mobile/user","findmobilecheck");
	}

	//忘记密码结束
	//获取分类
	public function classify(){
	    $sql="select * from `@#_fenlei` where `model`='1' and parentid ='0'";
	    $result=$this->db->Ylist($sql);
	     
	    echo json_encode($result);
	}
    // by xfx
    public function getZzfbList(){
        $_GET = array_change_key_case($_GET, CASE_LOWER);
        $fidx=htmlspecialchars($_GET[fidx])-1;

        $eidx=htmlspecialchars($_GET[eidx]);

        $xiangmuid=htmlspecialchars($_GET[codeid]);
        $huiyuan=$this->userinfo;
        $uid = $huiyuan['uid'];
        $orderlist['listItems']=$this->db->Ylist("SELECT * from `@#_sqfb` where `uid` = '$uid' ORDER BY time DESC limit $fidx,$eidx " );

        if(!$orderlist['listItems']){
            $yyslist['code']=-1;
            $yyslist['tips']="暂无记录";
        }else{
            $yyslist['code']=0;
            $yyslist['totalCount']=count($orderlist['listItems']);
            foreach($orderlist['listItems'] as $t => $v){
                $orderlist['listItems'][$t]['time'] = date('Y-m-d H:i:s',$v['time']);
            }
            $yyslist['listItems'] = $orderlist['listItems'];

        }

        echo json_encode($yyslist);


    }
    public function getFriendList(){
        $_GET = array_change_key_case($_GET, CASE_LOWER);
        $fidx=htmlspecialchars($_GET[fidx])-1;

        $eidx=htmlspecialchars($_GET[eidx]);

        $xiangmuid=htmlspecialchars($_GET[codeid]);
        $huiyuan=$this->userinfo;
        $uid = $huiyuan['uid'];
        $orderlist['listItems']=$this->db->Ylist("select * from `@#_fanyong_list` where `uid`='$huiyuan[uid]'  ORDER BY id DESC limit $fidx,$eidx " );
        $result = $this->getAll();
        if(!$orderlist['listItems']){
            $yyslist['code']=-1;
            $yyslist['tips']="暂无记录";
        }else{
            $yyslist['code']=0;
            $yyslist['totalCount']=count($orderlist['listItems']);

            foreach($orderlist['listItems'] as $v => $k){
                $user=$this->db->YOne("select email,mobile from `@#_yonghu` where `uid`='$k[fanyong_id]' ");
                if($user['mobile']){
                    $orderlist['listItems'][$v]['name'] = $user['mobile'];
                }else{
                    $orderlist['listItems'][$v]['name'] = $user['email'];
                }
                $ucount = $this->db->YOne("select COUNT(*) as count from `@#_fanyong_list` where `fanyong_id`='$k[fanyong_id]' and uid = $huiyuan[uid]");
                $orderlist['listItems'][$v]['count'] = $ucount['count'];
                foreach($result['alluser'] as $a){

                    if($a['user']['uid'] == $k[fanyong_id]){

                        $orderlist['listItems'][$v]['level'] = $a['level'];
                    }
                }
                $orderlist['listItems'][$v]['time'] = date('Y-m-d',$k['fanyong_time']);
            }

            $yyslist['listItems'] = $orderlist['listItems'];

        }

        echo json_encode($yyslist);


    }
    function getAll(){
        //查询返佣信息
        $key = 0;
        $alluser = array();
        $result = array();
        $mysql_model=System::DOWN_sys_class('model');
        $huiyuan=$this->userinfo;
        $son1=$mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$huiyuan[uid]'");
        $son1num = count($son1);
        $son2num = 0;
        $son3num = 0;
        $son4num = 0;
        $son5num = 0;
        $son6num = 0;

        $son1price = $son2price = $son3price = $son4price = $son5price = $son6price = 0;

        $son1_list = $son2_list = $son3_list = $son4_list =$son5_list =$son6_list = "";

        foreach ($son1 as $s1) {
            if ($s1['mobile']) {
                $son1_list .= '<a href='.LOCAL_PATH."/uname/".$s1[uid].".html >".$s1['mobile'] . "</a>,";
            } else {
                $son1_list .= '<a href='.LOCAL_PATH."/uname/".$s1[uid].".html  >".$s1['email'] . "</a>,";
            }
            $alluser[$key]['user'] = $s1;
            $alluser[$key]['level'] = 1;
            $key++;
            $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s1[uid]");
            $son1price += $temp['price'];

            $son2 = $mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s1[uid]'");
            $son2num += count($son2);
            foreach ($son2 as $s2) {
                if ($s2['mobile']) {
                    $son2_list .= '<a href='.LOCAL_PATH."/uname/".$s2[uid].".html >".$s2['mobile'] . "</a>,";
                } else {
                    $son2_list .= '<a href='.LOCAL_PATH."/uname/".$s2[uid].".html  >".$s2['email'] . "</a>,";
                }
                $alluser[$key]['user'] = $s2;
                $alluser[$key]['level'] = 2;
                $key++;
                $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s2[uid]");
                $son2price += $temp['price'];

                $son3 = $mysql_model->Ylist("select * from `@#_yonghu`  as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s2[uid]' ");
                $son3num += count($son3);
                foreach ($son3 as $s3) {
                    if ($s3['mobile']) {
                        $son3_list .= '<a href='.LOCAL_PATH."/uname/".$s3[uid].".html  >".$s3['mobile'] . "</a>,";
                    } else {
                        $son3_list .= '<a href='.LOCAL_PATH."/uname/".$s3[uid].".html  >".$s3['email'] . "</a>,";
                    }
                    $alluser[$key]['user'] = $s3;
                    $alluser[$key]['level'] = 3;
                    $key++;
                    $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s3[uid]");
                    $son3price += $temp['price'];

                    $son4 = $mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s3[uid]' ");
                    $son4num += count($son4);
                    foreach ($son4 as $s4) {
                        if ($s4['mobile']) {
                            $son4_list .= '<a href='.LOCAL_PATH."/uname/".$s4[uid].".html >".$s4['mobile'] . "</a>,";
                        } else {
                            $son4_list .= '<a href='.LOCAL_PATH."/uname/".$s4[uid].".html >".$s4['email'] . "</a>,";
                        }
                        $alluser[$key]['user'] = $s4;
                        $alluser[$key]['level'] = 4;
                        $key++;
                        $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s4[uid]");
                        $son4price += $temp['price'];

                        $son5 = $mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s4[uid]' ");
                        $son5num += count($son5);
                        foreach ($son5 as $s5) {
                            if ($s5['mobile']) {
                                $son5_list .= '<a href='.LOCAL_PATH."/uname/".$s5[uid].".html >".$s5['mobile'] . "</a>,";
                            } else {
                                $son5_list .= '<a href='.LOCAL_PATH."/uname/".$s5[uid].".html >".$s5['email'] . "</a>,";
                            }
                            $alluser[$key]['user'] = $s5;
                            $alluser[$key]['level'] = 5;
                            $key++;
                            $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s5[uid]");
                            $son5price += $temp['price'];

                            $son6 = $mysql_model->Ylist("select * from `@#_yonghu` as y left join `@#_fanyong` as f on y.uid = f.uid  where  f.stuats = 1  and y.fid ='$s5[uid]' ");
                            $son6num += count($son6);
                            foreach ($son6 as $s6) {
                                if ($s6['mobile']) {
                                    $son6_list .= '<a href='.LOCAL_PATH."/uname/".$s6[uid].".html >".$s6['mobile'] . "</a>,";
                                } else {
                                    $son6_list .= '<a href='.LOCAL_PATH."/uname/".$s6[uid].".html >".$s6['email'] . "</a>,";
                                }
                                $alluser[$key]['user'] = $s6;
                                $alluser[$key]['level'] = 6;
                                $key++;
                                $temp = $this->db->YOne("select SUM(price) as price from `@#_fanyong_list` where `uid`='$huiyuan[uid]' and `fanyong_id` = $s6[uid]");
                                $son6price += $temp['price'];
                            }
                        }
                    }
                }
            }
        }

        $totalnum = $son2num + $son1num + $son3num + $son4num + $son5num + $son6num;

        $result['alluser'] = $alluser;
        $result['son1price'] = $son1price;
        $result['son2price'] = $son2price;
        $result['son3price'] = $son3price;
        $result['son4price'] = $son4price;
        $result['son5price'] = $son5price;
        $result['son6price'] = $son6price;

        $result['son1_list'] = $son1_list;
        $result['son2_list'] = $son2_list;
        $result['son3_list'] = $son3_list;
        $result['son4_list'] = $son4_list;
        $result['son5_list'] = $son5_list;
        $result['son6_list'] = $son6_list;

        $result['son1num'] = $son1num;
        $result['son2num'] = $son2num;
        $result['son3num'] = $son3num;
        $result['son4num'] = $son4num;
        $result['son5num'] = $son5num;
        $result['son6num'] = $son6num;
        $result['totalnum'] = $totalnum;
        return $result;
    }
	
	public function getCouponList(){
		
		$_GET = array_change_key_case($_GET, CASE_LOWER);
		$webname=$this->_yys['web_name'];
		$cate_band =htmlspecialchars($_GET[sortid]);
		//var_dump($cate_band);
		$select =htmlspecialchars($_GET[orderflag]);	
		$order =htmlspecialchars($_GET[orderflag]);
		$kaishi=htmlspecialchars($_GET[fidx]);
		$jieshu=htmlspecialchars($_GET[eidx]);
		$p =$kaishi;	
		
		$sun_cate = $this->db->Ylist("SELECT cateid from `@#_fenlei` where `parentid` = '$cate_band'");
		foreach($sun_cate as $v){
			$sun_id_str .= "'".$v['cateid']."'".",";
			//var_dump($sun_id_str);
		}		
		$newstr = substr($sun_id_str,0,strlen($sun_id_str)-1);
		if($newstr){
			if(!$select){
				$select = '10';
			}		
			if($cate_band){
				$fen1 = intval($cate_band);	
				$cate_band = 'list';			
			}
			if(empty($fen1)){
				$pinpai=$this->db->Ylist("select * from `@#_pinpai` where 1 order by `order` DESC");	
				$daohangs = '所有分类';	
			}else{
				$pinpai=$this->db->Ylist("select * from `@#_pinpai` where `cateid`='$fen1' order by `order` DESC");
				$daohangs=$this->db->YOne("select * from `@#_fenlei` where `cateid` = '$fen1' order by `order` DESC");			
				$daohangs = $daohangs['name'];			
			}	

			$fenlei=$this->db->Ylist("select * from `@#_fenlei` where `model` = '1'");

			//分页

			$end=$jieshu;

			//var_dump($end);
			$star=($p-1);
			//var_dump($star);
			$select_w = '';
			if($select == 10){
				$select_w = 'order by a.`sellNumber` ASC';
			}
			if($select == 20){
				$select_w = "and a.`renqi` = '1'";
			}
			if($select == 30){
				$select_w = 'order by a.`sellNumber` ASC';
			}
			if($select == 40){
				$select_w = 'order by a.`sellNumber` ASC';
			}
			if($select == 30){
				$select_w = 'order by a.`price` DESC';
			}
			if($select == 31){
				$select_w = 'order by a.`price` ASC';
			}
			if($select == 50){
				$select_w = 'order by a.`id` DESC';
			}
			if($select == 60){
				$select_w = 'order by a.`price` ASC';
			}

 
			if($fen1){		
				$count = $this->db->Ylist("select a.* from `@#_coupon` a left join `@#_coupon_code` b on (a.id = b.couponId or a.isCodePass = '0') where a.`cateid` in ($newstr) and a.`validStartTime` <= '$time' and a.`validEndTime` >= '$time' and (b.status = '0' or a.isCodePass = '0') group by a.id $select_w");
			}else{			
				$time = time();
				$count = $this->db->Ylist("select a.* from `@#_coupon` a left join `@#_coupon_code` b on (a.id = b.couponId or a.isCodePass = '0') where a.`validStartTime` <= '$time' and a.`validEndTime` >= '$time' and (b.status = '0' or a.isCodePass = '0') group by a.id $select_w");
			}
			
			if($fen1){
				$yyslist=$this->db->Ylist("select a.* from `@#_coupon` a left join `@#_coupon_code` b on (a.id = b.couponId or a.isCodePass = '0') where a.`cateid` in ($newstr) and a.`validStartTime` <= '$time' and a.`validEndTime` >= '$time' and (b.status = '0' or a.isCodePass = '0') group by a.id $select_w limit $star,$end");
			}else{	
				$yyslist=$this->db->Ylist("select a.* from `@#_coupon` a left join `@#_coupon_code` b on (a.id = b.couponId or a.isCodePass = '0') where a.`validStartTime` <= '$time' and a.`validEndTime` >= '$time' and (b.status = '0' or a.isCodePass = '0') group by a.id $select_w limit $star,$end");
			} 
		}

		if($yyslist){
			$yyslist1['code']=0;
			$yyslist1['count']=count($count);
			foreach($yyslist as $key=>$val){
				$yyslist1['listItems'][$key]['rowid']=0;
				$yyslist1['listItems'][$key]['goodsid'] = $val['id'];
				$yyslist1['listItems'][$key]['goodssnme'] = $val['title'];
				$yyslist1['listItems'][$key]['platform'] = $val['platform'];
				$yyslist1['listItems'][$key]['goodspic'] = YYS_LOCAL_PATH."/statics/uploads/".$val['thumb'];
				$yyslist1['listItems'][$key]['codeid'] = $val['id'];
				$yyslist1['listItems'][$key]['codeprice'] = $val['price'];
				$yyslist1['listItems'][$key]['codequantity'] = $val['number'];
				$yyslist1['listItems'][$key]['codesales'] = $val['sellNumber'];
				$yyslist1['listItems'][$key]['codesales2'] = $val['discountPrice'];
				$yyslist1['listItems'][$key]['codeperiod'] = $val['qishu'];
				$yyslist1['listItems'][$key]['codetype']=0;
				$yyslist1['listItems'][$key]['goodstag']=0;
				$yyslist1['listItems'][$key]['codelimitbuy']=0;
			}
		}else{
			$yyslist1['code']=1;
		}
		echo json_encode($yyslist1);
	}
	
	public function getNewBuy(){
		$list = $this->db->YList("select * from `@#_yonghu_yys_record` where FIND_IN_SET('已付款',`status`) order by time desc limit 10");
		if($list){
			$rand = rand(0,(count($list)-1));
			$data = $list[$rand];
			
			if((time()- $data['time']) >= 3600*24){
				$data['time'] = intval((time()- $data['time']) / 3600 / 24 ).'天前';	
			}elseif((time()- $data['time']) >= 3600){
				$data['time'] = intval((time()- $data['time']) / 3600 ).'小时前';
			}elseif((time()- $data['time']) >= 60){
				$data['time'] = intval((time()- $data['time']) / 60 ).'分钟前';
			}
			$data['time'] = $data['time'];
		}
		echo json_encode(array('status'=>1,'username'=>$data['username'],'uphoto'=>$data['uphoto'],'gonumber'=>$data['gonumber'],'time'=>$data['time']));
	}
	
	
	public function get_user_goods(){
		$type = $_REQUEST['datatype'];
		echo "fuck";
	}
}

?>